Class: Setsy::Attribute

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

Constant Summary collapse

KLASS_MAP =
{
    'true' => 'Boolean',
    'false' => 'Boolean',
    'trueclass' => 'Boolean',
    'falseclass' => 'Boolean',
    'fixnum' => 'Integer'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Attribute

Returns a new instance of Attribute.



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

def initialize(options)
  @attribute_value = options[:value]
  @default = options[:default]
  @options = options
end

Instance Method Details

#defaultObject



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

def default
  @default ||= cast(@default)
end

#default?Boolean

Returns:

  • (Boolean)


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

def default?
  value == default
end

#to_sObject



18
19
20
# File 'lib/setsy/attribute.rb', line 18

def to_s
  @to_s ||= cast(@attribute_value).to_s
end

#valueObject Also known as: as_json



22
23
24
# File 'lib/setsy/attribute.rb', line 22

def value
  @value ||= cast(@attribute_value)
end