Class: Brentano::Presenter
- Inherits:
-
Object
- Object
- Brentano::Presenter
- Defined in:
- lib/brentano/presenter.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#maximum_size ⇒ Object
Returns the value of attribute maximum_size.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
- #finish(&blk) ⇒ Object
-
#initialize(subject, options = {}) {|_self| ... } ⇒ Presenter
constructor
A new instance of Presenter.
- #method_missing(name, *args, &blk) ⇒ Object
- #proxy_respond_to? ⇒ Object
- #respond_to?(*args) ⇒ Boolean
- #to_sql ⇒ Object
Constructor Details
#initialize(subject, options = {}) {|_self| ... } ⇒ Presenter
Returns a new instance of Presenter.
12 13 14 15 16 17 |
# File 'lib/brentano/presenter.rb', line 12 def initialize(subject, = {}, &blk) @subject = subject @options = Hashie::Mash.new() yield self if block_given? finish end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &blk) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/brentano/presenter.rb', line 36 def method_missing(name, *args, &blk) if @collection.respond_to? name result = @collection.send(name, *args, &blk) if result.is_a? ActiveRecord::Relation self.dup.tap do |copy| copy.instance_eval { @collection = result } end else result end else super end end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
8 9 10 |
# File 'lib/brentano/presenter.rb', line 8 def collection @collection end |
#maximum_size ⇒ Object
Returns the value of attribute maximum_size.
8 9 10 |
# File 'lib/brentano/presenter.rb', line 8 def maximum_size @maximum_size end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/brentano/presenter.rb', line 8 def @options end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
8 9 10 |
# File 'lib/brentano/presenter.rb', line 8 def subject @subject end |
Instance Method Details
#as_json(*args) ⇒ Object
51 52 53 |
# File 'lib/brentano/presenter.rb', line 51 def as_json(*args) @collection.as_json(*args) end |
#finish(&blk) ⇒ Object
19 20 21 |
# File 'lib/brentano/presenter.rb', line 19 def finish(&blk) @collection = Brentano::Query.finish relation, .dup, &blk end |
#proxy_respond_to? ⇒ Object
10 |
# File 'lib/brentano/presenter.rb', line 10 alias_method :proxy_respond_to?, :respond_to? |
#respond_to?(*args) ⇒ Boolean
32 33 34 |
# File 'lib/brentano/presenter.rb', line 32 def respond_to?(*args) proxy_respond_to?(args[0]) || @collection.respond_to?(args[0]) end |
#to_sql ⇒ Object
55 56 57 |
# File 'lib/brentano/presenter.rb', line 55 def to_sql @collection.to_sql end |