Class: Clot::BaseDrop

Inherits:
Liquid::Drop
  • Object
show all
Extended by:
DropAssociation
Defined in:
lib/clot/base_drop.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DropAssociation

belongs_to, has_many

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

#sourceObject (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

.includedObject



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_labelObject



91
92
93
# File 'lib/clot/base_drop.rb', line 91

def collection_label
  "label field"
end

#dropped_classObject



83
84
85
# File 'lib/clot/base_drop.rb', line 83

def dropped_class
  @source.class
end

#eql?(comparison_object) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/clot/base_drop.rb', line 55

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

#errorsObject



87
88
89
# File 'lib/clot/base_drop.rb', line 87

def errors
  @source.errors
end

#idObject



79
80
81
# File 'lib/clot/base_drop.rb', line 79

def id
  @source.id
end