Class: Actions::Base
- Inherits:
-
Object
- Object
- Actions::Base
- Defined in:
- lib/actions/base.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#err ⇒ Object
Returns the value of attribute err.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #call(*args, &block) ⇒ Object
- #err_msg ⇒ Object
- #error(erro, data = nil) ⇒ Object
- #error? ⇒ Boolean
- #fail? ⇒ Boolean
- #get(attr) ⇒ Object
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
- #run ⇒ Object
- #set(attr, val) ⇒ Object
- #set_data(val) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 |
# File 'lib/actions/base.rb', line 5 def initialize(params = {}) @errors = [] @params = params end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/actions/base.rb', line 3 def data @data end |
#err ⇒ Object
Returns the value of attribute err.
3 4 5 |
# File 'lib/actions/base.rb', line 3 def err @err end |
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'lib/actions/base.rb', line 3 def params @params end |
Instance Method Details
#call(*args, &block) ⇒ Object
48 49 50 51 |
# File 'lib/actions/base.rb', line 48 def call(*args, &block) run(*args, &block) self end |
#err_msg ⇒ Object
18 19 20 |
# File 'lib/actions/base.rb', line 18 def err_msg @err ? @err.to_s.split('_').join(' ') : '' end |
#error(erro, data = nil) ⇒ Object
26 27 28 29 |
# File 'lib/actions/base.rb', line 26 def error(erro, data = nil) @data = data @err = erro end |
#error? ⇒ Boolean
14 15 16 |
# File 'lib/actions/base.rb', line 14 def error? !success? end |
#fail? ⇒ Boolean
22 23 24 |
# File 'lib/actions/base.rb', line 22 def fail? error? end |
#get(attr) ⇒ Object
40 41 42 |
# File 'lib/actions/base.rb', line 40 def get(attr) @data && @data[attr] end |
#run ⇒ Object
44 45 46 |
# File 'lib/actions/base.rb', line 44 def run raise NotImplementedError end |
#set(attr, val) ⇒ Object
35 36 37 38 |
# File 'lib/actions/base.rb', line 35 def set(attr, val) @data ||= {} @data[attr] = val end |
#set_data(val) ⇒ Object
31 32 33 |
# File 'lib/actions/base.rb', line 31 def set_data(val) @data = val end |
#success? ⇒ Boolean
10 11 12 |
# File 'lib/actions/base.rb', line 10 def success? @err == nil end |