Class: MemoryModel::Base::Fieldable::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/memory_model/base/fieldable/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = { }) ⇒ Field

Returns a new instance of Field.



6
7
8
9
# File 'lib/memory_model/base/fieldable/field.rb', line 6

def initialize(name, options={ })
  @name    = name.to_sym
  @options = options.reverse_merge!({ readonly: false, comparable: true })
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/memory_model/base/fieldable/field.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/memory_model/base/fieldable/field.rb', line 3

def options
  @options
end

Instance Method Details

#==(other_object) ⇒ Object



11
12
13
# File 'lib/memory_model/base/fieldable/field.rb', line 11

def ==(other_object)
  self.to_sym == other_object.to_sym
end

#comparable?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/memory_model/base/fieldable/field.rb', line 15

def comparable?
  !!@options[:comparable]
end

#defaultObject



19
20
21
# File 'lib/memory_model/base/fieldable/field.rb', line 19

def default
  @options[:default]
end

#readonly?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/memory_model/base/fieldable/field.rb', line 23

def readonly?
  !!@options[:readonly]
end

#to_sObject



31
32
33
# File 'lib/memory_model/base/fieldable/field.rb', line 31

def to_s
  @name.to_s
end

#to_symObject



27
28
29
# File 'lib/memory_model/base/fieldable/field.rb', line 27

def to_sym
  @name.to_sym
end