Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ def export representer, model | |
else | ||
hash[key] = object | ||
end | ||
|
||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'active_support/concern' | ||
require 'active_support/core_ext' | ||
|
||
module Vintner | ||
module CollectionRepresenter | ||
extend ::ActiveSupport::Concern | ||
|
||
def initialize collection | ||
@collection = collection | ||
end | ||
|
||
def to_json | ||
self.class.export(@collection).to_json | ||
end | ||
|
||
|
||
module ClassMethods | ||
mattr_reader :collection | ||
|
||
def representer representer_klass | ||
@@collection = Collection.new(name, representer_klass) | ||
end | ||
|
||
def representation &block | ||
return @representation unless block_given? | ||
|
||
@representation = Representation.new &block | ||
end | ||
|
||
def export collection | ||
@representation.export(self, collection) | ||
end | ||
|
||
def represents_model? | ||
false | ||
end | ||
|
||
def represents_collection? | ||
true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters