Class: Archangel::Liquid::Drop

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
lib/archangel/liquid/drop.rb

Overview

Liquid Drop for singular resources

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, _options = {}) ⇒ Drop

Initialize


40
41
42
# File 'lib/archangel/liquid/drop.rb', line 40

def initialize(object, _options = {})
  @object = object
end

Class Attribute Details

._associationsObject

Returns the value of attribute _associations


13
14
15
# File 'lib/archangel/liquid/drop.rb', line 13

def _associations
  @_associations
end

._attributesObject

Returns the value of attribute _attributes


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

def _attributes
  @_attributes
end

Class Method Details

.attributes(*attrs) ⇒ Object

Build attributes


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/archangel/liquid/drop.rb', line 25

def self.attributes(*attrs)
  @_attributes.concat attrs

  attrs.each do |attr|
    next if method_defined?(attr)

    define_method(attr) do
      object.send(attr) if object.methods.include?(attr)
    end
  end
end

Instance Method Details

#as_json(options = {}) ⇒ Object

Object as JSON

Returns:

  • (Object)

    the JSON object


61
62
63
# File 'lib/archangel/liquid/drop.rb', line 61

def as_json(options = {})
  attributes.as_json(options)
end

#attributesHash

Hash of attributes

Returns:

  • (Hash)

    the attributes


49
50
51
52
53
54
# File 'lib/archangel/liquid/drop.rb', line 49

def attributes
  @attributes ||=
    self.class._attributes.dup.each_with_object({}) do |name, hash|
      hash[name.to_s] = send(name)
    end
end

#inspectString

Object inspect

Returns:

  • (String)

    object inspect


79
80
81
82
# File 'lib/archangel/liquid/drop.rb', line 79

def inspect
  "#<#{self.class.name} " \
    "@object: #{object.inspect} @attributes: #{attributes.inspect}>"
end

#to_json(options = {}) ⇒ Object

Object to JSON

Returns:

  • (Object)

    the JSON object


70
71
72
# File 'lib/archangel/liquid/drop.rb', line 70

def to_json(options = {})
  as_json.to_json(options)
end