Class: ActiveMocker::Field
- Inherits:
-
Object
- Object
- ActiveMocker::Field
- Defined in:
- lib/active_mocker/field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
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
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, ) @name = name @type = type @options = create_option_methods end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/active_mocker/field.rb', line 5 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/active_mocker/field.rb', line 5 def @options end |
#type ⇒ Object (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_methods ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/active_mocker/field.rb', line 18 def create_option_methods .each do |opt| key, value = opt.first self.instance_variable_set("@#{key}", value) define_singleton_method(key) {instance_variable_get("@#{key}")} end end |
#to_h ⇒ Object
14 15 16 |
# File 'lib/active_mocker/field.rb', line 14 def to_h {name: name, type: type, options: } end |