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
13
# File 'lib/active_mocker/field.rb', line 7

def initialize(name, type, options)
  @name    = name
  @type    = type
  @options = {}
  options.each{|hash| @options[hash.keys.first] = hash.values.first}
  create_option_methods
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#typeObject

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



21
22
23
24
25
26
# File 'lib/active_mocker/field.rb', line 21

def create_option_methods
  options.each do |key, value|
    self.instance_variable_set("@#{key}", value)
    self.class.send(:attr_accessor, key)
  end
end

#to_hObject Also known as: to_hash



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

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