Class: Actions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/actions/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/actions/base.rb', line 3

def data
  @data
end

#errObject

Returns the value of attribute err.



3
4
5
# File 'lib/actions/base.rb', line 3

def err
  @err
end

#paramsObject

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_msgObject



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

Returns:

  • (Boolean)


14
15
16
# File 'lib/actions/base.rb', line 14

def error?
  !success?
end

#fail?Boolean

Returns:

  • (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

#runObject

Raises:

  • (NotImplementedError)


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

Returns:

  • (Boolean)


10
11
12
# File 'lib/actions/base.rb', line 10

def success?
  @err == nil
end