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, Specifications::Common

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specification) ⇒ Abstract

Returns a new instance of Abstract.



10
11
12
13
14
15
16
17
18
19
# File 'lib/entity_schema/fields/abstract.rb', line 10

def initialize(specification)
  @name       ||= specification.name
  @owner_name   = specification.owner_name
  @src_key    ||= specification.src_key

  @public_getter = specification.public_getter?
  @public_setter = specification.public_setter?

  @ivar_name = :"@#{name}"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/entity_schema/fields/abstract.rb', line 8

def name
  @name
end

#src_keyObject (readonly)

Returns the value of attribute src_key.



8
9
10
# File 'lib/entity_schema/fields/abstract.rb', line 8

def src_key
  @src_key
end

Instance Method Details

#get(_obj) ⇒ Object

:nocov:

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/entity_schema/fields/abstract.rb', line 40

def get(_obj)
  raise NotImplementedError
end

#given?(obj) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/entity_schema/fields/abstract.rb', line 31

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

#public_get(obj) ⇒ Object



26
27
28
29
# File 'lib/entity_schema/fields/abstract.rb', line 26

def public_get(obj)
  raise_public('Getter') unless @public_getter
  get(obj)
end

#public_getter?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/entity_schema/fields/abstract.rb', line 49

def public_getter?
  @public_getter
end

#public_set(obj, value) ⇒ Object



21
22
23
24
# File 'lib/entity_schema/fields/abstract.rb', line 21

def public_set(obj, value)
  raise_public('Setter') unless @public_setter
  set(obj, value)
end

#public_setter?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/entity_schema/fields/abstract.rb', line 53

def public_setter?
  @public_setter
end

#serialize(obj, output) ⇒ Object

:nocov:



45
46
47
# File 'lib/entity_schema/fields/abstract.rb', line 45

def serialize(obj, output)
  output[src_key] = read(obj) if given?(obj)
end

#set(obj, value) ⇒ Object



35
36
37
# File 'lib/entity_schema/fields/abstract.rb', line 35

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