Class: Rasti::Model::Attribute

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Attribute.



7
8
9
10
11
# File 'lib/rasti/model/attribute.rb', line 7

def initialize(name, type, options={})
  @name = name
  @type = type
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rasti/model/attribute.rb', line 5

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/rasti/model/attribute.rb', line 5

def type
  @type
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rasti/model/attribute.rb', line 13

def default?
  options.key? :default
end

#default_valueObject



17
18
19
# File 'lib/rasti/model/attribute.rb', line 17

def default_value
  options.fetch(:default)
end

#option(name) ⇒ Object



21
22
23
# File 'lib/rasti/model/attribute.rb', line 21

def option(name)
  options[name]
end

#to_sObject Also known as: inspect



25
26
27
# File 'lib/rasti/model/attribute.rb', line 25

def to_s
  "#{self.class}[name: #{name.inspect}, type: #{type.inspect}, options: #{options.inspect}]"
end