class EntitySchema::Fields::Abstract
Specification
for fiend behaviour: internal and external
will be used for build Field object and for setup Field object
Constants
- Specification
Attributes
ivar_name[R]
name[R]
owner_name[R]
serialize_method[R]
specification[R]
src_key[R]
Public Class Methods
new(options)
click to toggle source
# File lib/entity_schema/fields/abstract.rb, line 12 def initialize(options) @name ||= options[:name] @owner_name = options[:owner_name] @src_key ||= options[:src_key] @ivar_name = :"@#{name}" @specification = Specification.new @specification.public_getter = options[:public_getter] @specification.public_setter = options[:public_setter] end
Public Instance Methods
get(_obj)
click to toggle source
:nocov:
# File lib/entity_schema/fields/abstract.rb, line 42 def get(_obj) raise NotImplementedError end
given?(obj)
click to toggle source
# File lib/entity_schema/fields/abstract.rb, line 33 def given?(obj) obj.instance_variable_defined?(ivar_name) end
public_get(obj)
click to toggle source
# File lib/entity_schema/fields/abstract.rb, line 28 def public_get(obj) raise_public('Getter') unless specification.public_getter get(obj) end
public_set(obj, value)
click to toggle source
# File lib/entity_schema/fields/abstract.rb, line 23 def public_set(obj, value) raise_public('Setter') unless specification.public_setter set(obj, value) end
serialize(obj, output)
click to toggle source
:nocov:
# File lib/entity_schema/fields/abstract.rb, line 47 def serialize(obj, output) output[src_key] = read(obj) if given?(obj) end
set(obj, value)
click to toggle source
# File lib/entity_schema/fields/abstract.rb, line 37 def set(obj, value) write(obj, value) end
Private Instance Methods
raise_public(subject)
click to toggle source
# File lib/entity_schema/fields/abstract.rb, line 55 def raise_public(subject) raise NameError, "Private #{subject} called for field `#{name}` of `#{owner_name}`" end
read(obj)
click to toggle source
# File lib/entity_schema/fields/abstract.rb, line 59 def read(obj) obj.instance_variable_get(ivar_name) end
write(obj, value)
click to toggle source
# File lib/entity_schema/fields/abstract.rb, line 63 def write(obj, value) obj.instance_variable_set(ivar_name, value) end