Class: Yukata::Attribute

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

Overview

A single attribute that is attached to a model

Author:

  • Matthew A. Johnston

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



10
11
12
13
14
15
16
17
18
# File 'lib/yukata/attribute.rb', line 10

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.



6
7
8
# File 'lib/yukata/attribute.rb', line 6

def type
  @type
end

Instance Method Details

#defaultObject



20
21
22
# File 'lib/yukata/attribute.rb', line 20

def default
  @default.call
end