Class: Goaltender::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Goaltender
Defined in:
lib/goaltender/base.rb

Constant Summary

Constants included from Goaltender

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Goaltender

included

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

#inputsObject

Returns the value of attribute inputs.



7
8
9
# File 'lib/goaltender/base.rb', line 7

def inputs
  @inputs
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/goaltender/base.rb', line 7

def params
  @params
end

Instance Method Details

#saveObject



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_hObject



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