Class: Holotype::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/holotype/attribute.rb,
lib/holotype/attribute/definition.rb,
lib/holotype/attribute/read_only_error.rb,
lib/holotype/attribute/immutable_value_error.rb,
lib/holotype/attribute/frozen_modification_error.rb,
lib/holotype/attribute/definition/no_value_class_error.rb,
lib/holotype/attribute/definition/default_conflict_error.rb,
lib/holotype/attribute/definition/required_conflict_error.rb,
lib/holotype/attribute/definition/no_collection_class_error.rb

Defined Under Namespace

Classes: Definition, FrozenModificationError, ImmutableValueError, ReadOnlyError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, definition, **options) ⇒ Attribute

Returns a new instance of Attribute.



12
13
14
15
16
17
# File 'lib/holotype/attribute.rb', line 12

def initialize owner, definition, **options
  @definition = definition
  @owner      = owner

  set_value options[:value] if options.key? :value
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



10
11
12
# File 'lib/holotype/attribute.rb', line 10

def definition
  @definition
end

#ownerObject (readonly)

Returns the value of attribute owner.



10
11
12
# File 'lib/holotype/attribute.rb', line 10

def owner
  @owner
end

Instance Method Details

#nameObject



19
20
21
# File 'lib/holotype/attribute.rb', line 19

def name
  definition.name
end

#valueObject



23
24
25
26
# File 'lib/holotype/attribute.rb', line 23

def value
  set_value definition.default owner unless @has_value
  @value
end

#value=(new_value) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/holotype/attribute.rb', line 28

def value= new_value
  raise ImmutableValueError.new     name if definition.immutable?
  raise FrozenModificationError.new name if owner.frozen?
  raise ReadOnlyError.new           name if definition.read_only?

  set_value new_value
end