Class: Goaltender::Base
- Inherits:
-
Object
- Object
- Goaltender::Base
- Includes:
- ActiveModel::Model, Goaltender
- Defined in:
- lib/goaltender/base.rb
Constant Summary
Constants included from Goaltender
Instance Attribute Summary collapse
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(args) ⇒ Base
constructor
A new instance of Base.
- #save ⇒ Object
- #to_h ⇒ Object
Methods included from Goaltender
Constructor Details
#initialize(args) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 |
# File 'lib/goaltender/base.rb', line 10 def initialize(args) @params = HashWithIndifferentAccess.new(args) @inputs = set_inputs after_init(@params) end |
Instance Attribute Details
#inputs ⇒ Object
Returns the value of attribute inputs.
7 8 9 |
# File 'lib/goaltender/base.rb', line 7 def inputs @inputs end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/goaltender/base.rb', line 7 def params @params end |
Instance Method Details
#save ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/goaltender/base.rb', line 25 def save before_save success = valid_form? ? persist! : false if success after_save true else false end end |
#to_h ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/goaltender/base.rb', line 16 def to_h hash = {} inputs.each do |input| value = instance_variable_get("@#{input.variable_name}") hash[input.variable_name] = value end hash end |