Class: BaseComposer

Inherits:
Object
  • Object
show all
Defined in:
lib/ViewComposer/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.



22
23
24
25
26
27
28
29
30
# File 'lib/ViewComposer/base_composer.rb', line 22

def initialize(model:, composable_objects: [] )
  set_inherited_methods_list
  @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.



12
13
14
# File 'lib/ViewComposer/base_composer.rb', line 12

def _attributes
  @_attributes
end

._inherited_methodsObject

Returns the value of attribute _inherited_methods.



12
13
14
# File 'lib/ViewComposer/base_composer.rb', line 12

def _inherited_methods
  @_inherited_methods
end

._instance_attrsObject

Returns the value of attribute _instance_attrs.



12
13
14
# File 'lib/ViewComposer/base_composer.rb', line 12

def _instance_attrs
  @_instance_attrs
end

._model_methodsObject

Returns the value of attribute _model_methods.



12
13
14
# File 'lib/ViewComposer/base_composer.rb', line 12

def _model_methods
  @_model_methods
end

Class Method Details

.attributes(*attrs) ⇒ Object



32
33
34
35
# File 'lib/ViewComposer/base_composer.rb', line 32

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

.inherited(base) ⇒ Object



37
38
39
40
41
# File 'lib/ViewComposer/base_composer.rb', line 37

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

Instance Method Details

#hash_attrsObject



43
44
45
# File 'lib/ViewComposer/base_composer.rb', line 43

def hash_attrs
  @json_hash
end

#to_jsonObject



47
48
49
# File 'lib/ViewComposer/base_composer.rb', line 47

def to_json
  @json_hash.to_json
end