class SonJay::ObjectModel
Attributes
model_content[R]
Public Class Methods
new()
click to toggle source
# File lib/son_jay/object_model.rb, line 14 def initialize definitions = self.class.property_definitions @model_content = ObjectModel::Content.new( definitions, self.class.extras_allowed? ) end
Private Class Methods
_apply_property_definitions(definitions)
click to toggle source
# File lib/son_jay/object_model.rb, line 107 def _apply_property_definitions(definitions) definitions.each do |d| name = d.name property_defs_module.module_eval <<-CODE def #{name} ; model_content[#{name.inspect}] ; end def #{name}=(value) ; model_content[#{name.inspect}] = value ; end CODE end end
_evaluate_property_definitions()
click to toggle source
# File lib/son_jay/object_model.rb, line 78 def _evaluate_property_definitions _populate_property_definitions _validate_model_dependencies! _apply_property_definitions property_definitions _property_definitions end
_inherited_property_definitions()
click to toggle source
# File lib/son_jay/object_model.rb, line 93 def _inherited_property_definitions self == SonJay::ObjectModel ? PropertyDefinitions.new : superclass.property_definitions end
_populate_property_definitions()
click to toggle source
# File lib/son_jay/object_model.rb, line 85 def _populate_property_definitions @property_definitions = _inherited_property_definitions + PropertyDefinitions.from_initializations( _property_initializations ) end
_property_definitions()
click to toggle source
# File lib/son_jay/object_model.rb, line 99 def _property_definitions @property_definitions end
_property_initializations()
click to toggle source
# File lib/son_jay/object_model.rb, line 103 def _property_initializations @property_initializations ||= [] end
_validate_model_dependencies!(dependants=Set.new)
click to toggle source
# File lib/son_jay/object_model.rb, line 127 def _validate_model_dependencies!(dependants=Set.new) raise InfiniteRegressError if dependants.include?(self) dependants << self property_definitions.hard_model_dependencies.each do |d| next unless d.respond_to?( :_validate_model_dependencies!, true ) d.send :_validate_model_dependencies!, dependants end end
allow_extras(allowed = true)
click to toggle source
# File lib/son_jay/object_model.rb, line 74 def allow_extras(allowed = true) @extras_allowed = allowed end
extras_allowed?()
click to toggle source
# File lib/son_jay/object_model.rb, line 60 def extras_allowed? @extras_allowed ||= false end
properties(&property_initializations)
click to toggle source
# File lib/son_jay/object_model.rb, line 70 def properties(&property_initializations) _property_initializations << property_initializations end
property_definitions()
click to toggle source
# File lib/son_jay/object_model.rb, line 64 def property_definitions @property_definitions ||= _evaluate_property_definitions end
property_defs_module()
click to toggle source
# File lib/son_jay/object_model.rb, line 117 def property_defs_module @property_defs_module ||= begin Module.new.tap do |mod| const_set :HasPropertyAccessors, mod include mod end end end
Public Instance Methods
[](name)
click to toggle source
# File lib/son_jay/object_model.rb, line 35 def [](name) name = self.class.property_definitions.name_from(name) source = property_store_for( name ) source[ name ] end
[]=(name, value)
click to toggle source
# File lib/son_jay/object_model.rb, line 29 def []=(name, value) name = self.class.property_definitions.name_from(name) target = property_store_for( name ) target[ name ] = value end
fetch(name)
click to toggle source
# File lib/son_jay/object_model.rb, line 41 def fetch(name) model_content.fetch( name ) end
to_h()
click to toggle source
# File lib/son_jay/object_model.rb, line 25 def to_h model_content.to_h end
to_json(*args)
click to toggle source
# File lib/son_jay/object_model.rb, line 21 def to_json(*args) model_content.to_json( *args ) end
Private Instance Methods
property_store_for(name_string)
click to toggle source
# File lib/son_jay/object_model.rb, line 47 def property_store_for(name_string) store = model_content if ( self.class.extras_allowed? && (! self.class.property_definitions.include_name?(name_string) ) ) then store = model_content.extra end store end