class SonJay::ObjectModel::Content::Abstract
Attributes
model_properties[R]
property_definitions[R]
Public Class Methods
new(property_definitions)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 13 def initialize(property_definitions) @property_definitions = property_definitions @data = ObjectModel::ContentData.new @model_properties = Set.new init_properties \ *property_definitions.partition { |md| !! md.model_class } end
Public Instance Methods
[](name)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 27 def [](name) name = property_definitions.name_from(name) @data[name] end
[]=(name, value)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 39 def []=(name, value) name = property_definitions.name_from(name) raise PropertyNameError.new(name) unless @data.has_key?(name) @data[name] = value end
clone()
click to toggle source
Calls superclass method
# File lib/son_jay/object_model/content/abstract.rb, line 86 def clone new_copy = super unless new_copy.frozen? new_copy.instance_variable_set :@data, @data.clone new_copy.instance_variable_set :@model_properties, @model_properties.clone end new_copy end
dup()
click to toggle source
Calls superclass method
# File lib/son_jay/object_model/content/abstract.rb, line 79 def dup new_copy = super new_copy.instance_variable_set :@data, @data.dup new_copy.instance_variable_set :@model_properties, @model_properties.dup new_copy end
each()
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 69 def each raise NotImplementedError, "Subclass responsibility" end
extra()
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 60 def extra raise NotImplementedError, "Subclass responsibility" end
fetch(name)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 32 def fetch(name) name = property_definitions.name_from(name) @data.fetch(name) rescue KeyError raise PropertyNameError.new(name) end
freeze()
click to toggle source
Calls superclass method
# File lib/son_jay/object_model/content/abstract.rb, line 73 def freeze super @data.freeze self end
load_data(data)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 45 def load_data(data) data.each_pair do |name, value| load_property name, value end end
load_property(name, value)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 51 def load_property(name, value) name = property_definitions.name_from(name) if @data.has_key?( name ) load_defined_property name, value else load_extra_property name, value end end
to_json(options = ::JSON::State.new)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 64 def to_json(options = ::JSON::State.new) options = ::JSON::State.new(options) unless options.kind_of?(::JSON::State) hash_for_json.to_json( options ) end
Private Instance Methods
hash_for_json()
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 120 def hash_for_json raise NotImplementedError, "Subclass responsibility" end
init_properties(model_property_defs, value_property_defs)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 97 def init_properties(model_property_defs, value_property_defs) value_property_defs.each do |d| @data[d.name] = nil end model_property_defs.each do |d| @data[d.name] = d.model_class.new @model_properties << d.name end end
load_defined_property(name_string, value)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 108 def load_defined_property(name_string, value) if @model_properties.include?( name_string ) @data[ name_string ].model_content.load_data value else @data[ name_string ] = value end end
load_extra_property(name_string, value)
click to toggle source
# File lib/son_jay/object_model/content/abstract.rb, line 116 def load_extra_property(name_string, value) raise NotImplementedError, "Subclass responsibility" end