Class: Clot::BaseDrop
- Inherits:
-
Liquid::Drop
- Object
- Liquid::Drop
- Clot::BaseDrop
- Extended by:
- DropAssociation
- Defined in:
- lib/clot/base_drop.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
- .included ⇒ Object
-
.liquify(current_context, *records, &block) ⇒ Object
converts an array of records to an array of liquid drops, and assigns the given context to each of them.
- .method_missing(symbol, *args) ⇒ Object
Instance Method Summary collapse
- #==(comparison_object) ⇒ Object
- #before_method(method) ⇒ Object
- #collection_label ⇒ Object
- #dropped_class ⇒ Object
- #eql?(comparison_object) ⇒ Boolean
- #errors ⇒ Object
- #id ⇒ Object
-
#initialize(source) ⇒ BaseDrop
constructor
A new instance of BaseDrop.
Methods included from DropAssociation
Constructor Details
#initialize(source) ⇒ BaseDrop
Returns a new instance of BaseDrop.
46 47 48 49 |
# File 'lib/clot/base_drop.rb', line 46 def initialize(source) @source = source @liquid = liquid_attributes.inject({}) { |h, k| h.update k.to_s => @source.send(k) } end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
43 44 45 |
# File 'lib/clot/base_drop.rb', line 43 def source @source end |
Class Method Details
.included ⇒ Object
37 38 39 |
# File 'lib/clot/base_drop.rb', line 37 def self.included include Rails.application.routes.url_helpers end |
.liquify(current_context, *records, &block) ⇒ Object
converts an array of records to an array of liquid drops, and assigns the given context to each of them
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/clot/base_drop.rb', line 64 def self.liquify(current_context, *records, &block) i = -1 records = records.inject [] do |all, r| i+=1 attrs = (block && block.arity == 1) ? [r] : [r, i] all << (block ? block.call(*attrs) : r.to_liquid) all.last.context = current_context if all.last.is_a?(Liquid::Drop) all end records.compact! records end |
.method_missing(symbol, *args) ⇒ Object
95 96 97 |
# File 'lib/clot/base_drop.rb', line 95 def self.method_missing(symbol, *args) [symbol] end |
Instance Method Details
#==(comparison_object) ⇒ Object
59 60 61 |
# File 'lib/clot/base_drop.rb', line 59 def ==(comparison_object) self.source == (comparison_object.is_a?(self.class) ? comparison_object.source : comparison_object) end |
#before_method(method) ⇒ Object
51 52 53 |
# File 'lib/clot/base_drop.rb', line 51 def before_method(method) @liquid[method.to_s] end |
#collection_label ⇒ Object
91 92 93 |
# File 'lib/clot/base_drop.rb', line 91 def collection_label "label field" end |
#dropped_class ⇒ Object
83 84 85 |
# File 'lib/clot/base_drop.rb', line 83 def dropped_class @source.class end |
#eql?(comparison_object) ⇒ Boolean
55 56 57 |
# File 'lib/clot/base_drop.rb', line 55 def eql?(comparison_object) self == (comparison_object) end |
#errors ⇒ Object
87 88 89 |
# File 'lib/clot/base_drop.rb', line 87 def errors @source.errors end |
#id ⇒ Object
79 80 81 |
# File 'lib/clot/base_drop.rb', line 79 def id @source.id end |