Class: Croesus::Attribute

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

Overview

A single attribute that is attached to a model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = String, options = {}) ⇒ Attribute

Returns a new instance of Attribute.

Parameters:

  • type (Class) (defaults to: String)

    the class this attribute represents

  • options (Hash) (defaults to: {})

    extra options that can be prescribed



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

def initialize(type = String, options = {})
  @type = type

  if options[:default].is_a?(Proc)
    @default = options[:default]
  else
    @default = -> { options[:default] }
  end
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#defaultObject



37
38
39
# File 'lib/croesus/attribute.rb', line 37

def default
  @default.call
end