Class: ActiveMocker::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mocker/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options) ⇒ Field

Returns a new instance of Field.



7
8
9
10
11
12
# File 'lib/active_mocker/field.rb', line 7

def initialize(name, type, options)
  @name    = name
  @type    = type
  @options = options
  create_option_methods
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/active_mocker/field.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/active_mocker/field.rb', line 5

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/active_mocker/field.rb', line 5

def type
  @type
end

Instance Method Details

#create_option_methodsObject



18
19
20
21
22
23
24
# File 'lib/active_mocker/field.rb', line 18

def create_option_methods
  options.each do |opt|
    key, value = opt.first
    self.instance_variable_set("@#{key}", value)
    define_singleton_method(key) {instance_variable_get("@#{key}")}
  end
end

#to_hObject



14
15
16
# File 'lib/active_mocker/field.rb', line 14

def to_h
  {name: name, type: type, options: options}
end