Class: ViewComposer::BaseComposer

Inherits:
Object
  • Object
show all
Defined in:
lib/view_composer/base_composer.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, composable_objects: []) ⇒ BaseComposer

Returns a new instance of BaseComposer.



12
13
14
15
16
17
18
19
20
# File 'lib/view_composer/base_composer.rb', line 12

def initialize(model:, composable_objects: [] )
  @model = model
  @json_hash = {}

  set_model_methods
  set_attributes_methods
  setup_comp_objs(composable_objects)
  methods_to_hash
end

Class Attribute Details

._attributesObject

Returns the value of attribute _attributes.



8
9
10
# File 'lib/view_composer/base_composer.rb', line 8

def _attributes
  @_attributes
end

Class Method Details

.attributes(*attrs) ⇒ Object



22
23
24
# File 'lib/view_composer/base_composer.rb', line 22

def self.attributes(*attrs)
  Array(attrs).each {|attr| self._attributes << attr}
end

.inherited(base) ⇒ Object



26
27
28
29
# File 'lib/view_composer/base_composer.rb', line 26

def self.inherited(base)
  super
  base._attributes = self._attributes.dup
end

Instance Method Details

#hash_attrsObject



31
32
33
# File 'lib/view_composer/base_composer.rb', line 31

def hash_attrs
  @json_hash
end

#to_jsonObject



35
36
37
# File 'lib/view_composer/base_composer.rb', line 35

def to_json
  @json_hash.to_json
end