Class: Extant::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/extant/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, definition) ⇒ Attribute

Returns a new instance of Attribute.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/extant/attribute.rb', line 5

def initialize(name, value, definition)
  self.name = name
  self.has_been_coereced = false
  self.definition = definition

  if UnsetValue == value
    @value = nil
    self.is_unset = true
  else
    set_value(value)
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/extant/attribute.rb', line 3

def name
  @name
end

#pre_coerce_valueObject

Returns the value of attribute pre_coerce_value.



3
4
5
# File 'lib/extant/attribute.rb', line 3

def pre_coerce_value
  @pre_coerce_value
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/extant/attribute.rb', line 3

def value
  @value
end

Instance Method Details

#coerced?Boolean

Returns:

  • (Boolean)


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

def coerced?
  !!has_been_coereced
end

#coercer_nameObject



39
40
41
# File 'lib/extant/attribute.rb', line 39

def coercer_name
  coercer_class.try(:coercer_name)
end

#has_changed?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/extant/attribute.rb', line 27

def has_changed?
  !!value_has_changed
end

#inspectObject



43
44
45
# File 'lib/extant/attribute.rb', line 43

def inspect
  "<Extant::Attribute:#{self.object_id} Name: :#{name} Value: #{value.inspect}>"
end

#set?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/extant/attribute.rb', line 35

def set?
  !is_unset
end

#unset?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/extant/attribute.rb', line 31

def unset?
  !set?
end