Class: Liquid::BaseDrop

Inherits:
Drop
  • Object
show all
Defined in:
lib/liquid/base_drop.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ BaseDrop

Returns a new instance of BaseDrop.



9
10
11
12
# File 'lib/liquid/base_drop.rb', line 9

def initialize(source)
  @source = source
  @liquid = liquid_attributes.inject({}) { |h, k| h.update k.to_s => @source.send(k) }
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/liquid/base_drop.rb', line 5

def source
  @source
end

Class Method Details

.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



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/liquid/base_drop.rb', line 27

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



58
59
60
# File 'lib/liquid/base_drop.rb', line 58

def self.method_missing(symbol, *args)
  [symbol]
end

Instance Method Details

#==(comparison_object) ⇒ Object



22
23
24
# File 'lib/liquid/base_drop.rb', line 22

def ==(comparison_object)
  self.source == (comparison_object.is_a?(self.class) ? comparison_object.source : comparison_object)
end

#before_method(method) ⇒ Object



14
15
16
# File 'lib/liquid/base_drop.rb', line 14

def before_method(method)
  @liquid[method.to_s]
end

#collection_labelObject



54
55
56
# File 'lib/liquid/base_drop.rb', line 54

def collection_label
  "label field"
end

#dropped_classObject



46
47
48
# File 'lib/liquid/base_drop.rb', line 46

def dropped_class
  @source.class
end

#eql?(comparison_object) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/liquid/base_drop.rb', line 18

def eql?(comparison_object)
  self == (comparison_object)
end

#errorsObject



50
51
52
# File 'lib/liquid/base_drop.rb', line 50

def errors
  @source.errors
end

#idObject



42
43
44
# File 'lib/liquid/base_drop.rb', line 42

def id
  @source.id
end