Class: EntitySchema::Fields::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/entity_schema/fields/abstract.rb

Overview

Specification for fiend behaviour: internal and external

will be used for build Field object and for setup Field object

Direct Known Subclasses

Object, Property

Defined Under Namespace

Classes: Specification

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Abstract

Returns a new instance of Abstract.



12
13
14
15
16
17
18
19
20
21
# 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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/entity_schema/fields/abstract.rb', line 10

def name
  @name
end

#specificationObject (readonly)

Returns the value of attribute specification.



10
11
12
# File 'lib/entity_schema/fields/abstract.rb', line 10

def specification
  @specification
end

#src_keyObject (readonly)

Returns the value of attribute src_key.



10
11
12
# File 'lib/entity_schema/fields/abstract.rb', line 10

def src_key
  @src_key
end

Instance Method Details

#get(_obj) ⇒ Object

:nocov:

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/entity_schema/fields/abstract.rb', line 42

def get(_obj)
  raise NotImplementedError
end

#given?(obj) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/entity_schema/fields/abstract.rb', line 33

def given?(obj)
  obj.instance_variable_defined?(ivar_name)
end

#public_get(obj) ⇒ Object



28
29
30
31
# 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) ⇒ Object



23
24
25
26
# 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) ⇒ Object

:nocov:



47
48
49
# 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) ⇒ Object



37
38
39
# File 'lib/entity_schema/fields/abstract.rb', line 37

def set(obj, value)
  write(obj, value)
end