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



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ViewComposer/base_composer.rb', line 8

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

  @parent_methods = self.class.superclass.instance_methods(false)
  @composer_methods = self.class.instance_methods(false)
  @dont_redefine = @parent_methods + @composer_methods
  @_attrs = self.class._attributes
  set_attributes
  setup_comp_objs(composable_objects)
  methods_to_hash
end

Class Attribute Details

._attributesObject

Returns the value of attribute _attributes.



4
5
6
# File 'lib/ViewComposer/base_composer.rb', line 4

def _attributes
  @_attributes
end

Class Method Details

.attributes(*attrs) ⇒ Object



29
30
31
# File 'lib/ViewComposer/base_composer.rb', line 29

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

.inherited(base) ⇒ Object



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

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

Instance Method Details

#hash_attrsObject



21
22
23
# File 'lib/ViewComposer/base_composer.rb', line 21

def hash_attrs
  @json_hash
end

#to_jsonObject



25
26
27
# File 'lib/ViewComposer/base_composer.rb', line 25

def to_json
  @json_hash.to_json
end