class BaseComposer
Attributes
_attributes[RW]
_inherited_methods[RW]
_instance_attrs[RW]
_instance_defined_methods[RW]
_model_methods[RW]
Public Class Methods
attributes(*attrs)
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 34 def self.attributes(*attrs) self._instance_attrs = attrs Array(attrs).each {|attr| self._attributes << attr} end
inherited(base)
click to toggle source
Calls superclass method
# File lib/ViewComposer/base_composer.rb, line 39 def self.inherited(base) super base._attributes = self._attributes.dup base._inherited_methods = self._inherited_methods.dup base._model_methods = self._model_methods.dup end
new(model:, composable_objects: [] )
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 23 def initialize(model:, composable_objects: [] ) set_inherited_methods_list @model = model @json_hash = {} set_model_methods set_instance_defined_methods set_attributes_methods setup_comp_objs(composable_objects) methods_to_hash end
Public Instance Methods
hash_attrs()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 46 def hash_attrs @json_hash end
to_json()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 50 def to_json @json_hash.to_json end
Private Instance Methods
attributes()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 85 def attributes @attributes ||= self.class._attributes end
definable_methods()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 117 def definable_methods self.class._instance_defined_methods + self.class._model_methods end
define_methods(method_names, method_owner)
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 129 def define_methods(method_names, method_owner) method_names.uniq.each do |attr| self.class.send(:define_method, attr) do method_owner.send(attr) end end end
get_all_methods()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 97 def get_all_methods (attributes + inherited_methods + instance_methods).uniq end
inherited_methods()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 93 def inherited_methods @inherted_methods ||= self.class._inherited_methods end
instance_attributes()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 76 def instance_attributes @instance_attributes ||= self.class._instance_attrs || [] end
instance_methods()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 89 def instance_methods @instance_methods ||= self.class.instance_methods(false) end
methods_to_hash()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 106 def methods_to_hash methods = get_all_methods - EXCLUDED_METHODS methods.each do |method| @json_hash[method] = self.send(method) end end
set_attributes_methods()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 113 def set_attributes_methods define_methods(definable_methods, @model) end
set_inherited_methods_list()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 101 def set_inherited_methods_list _methods = self.class.superclass.instance_methods(false) - EXCLUDED_METHODS self.class._inherited_methods += _methods end
set_instance_defined_methods()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 68 def set_instance_defined_methods if self.class._instance_defined_methods != nil self.class._instance_defined_methods += self.class._model_methods else self.class._instance_defined_methods = self.class._model_methods end end
set_model_methods()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 56 def set_model_methods new_model_methods = attributes - instance_methods new_model_methods = new_model_methods - inherited_methods new_model_methods = new_model_methods + super_model_methods if self.class.superclass != Object self.class._model_methods = super_model_methods + new_model_methods else self.class._model_methods = new_model_methods end end
setup_comp_objs(comp_objs_array)
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 121 def setup_comp_objs(comp_objs_array) @comp_objs = comp_objs_array.map do |obj| object_instance = obj.new(@model) define_methods(obj.instance_methods(false), object_instance) return object_instance end end
super_model_methods()
click to toggle source
# File lib/ViewComposer/base_composer.rb, line 80 def super_model_methods return [] if self.class.superclass === Object @super_model ||= self.class.superclass._model_methods || [] end