Class: ActiveMocker::Field
- Inherits:
-
Object
- Object
- ActiveMocker::Field
- Defined in:
- lib/active_mocker/field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #create_option_methods ⇒ Object
-
#initialize(name, type, options) ⇒ Field
constructor
A new instance of Field.
- #to_h ⇒ Object (also: #to_hash)
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, ) @name = name @type = type @options = {} .each{|hash| @options[hash.keys.first] = hash.values.first} create_option_methods end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/active_mocker/field.rb', line 5 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/active_mocker/field.rb', line 5 def @options end |
#type ⇒ Object
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_methods ⇒ Object
21 22 23 24 25 26 |
# File 'lib/active_mocker/field.rb', line 21 def create_option_methods .each do |key, value| self.instance_variable_set("@#{key}", value) self.class.send(:attr_accessor, key) end end |
#to_h ⇒ Object Also known as: to_hash
15 16 17 |
# File 'lib/active_mocker/field.rb', line 15 def to_h {name: name, type: type, options: } end |