Class: Sails::Service::Base

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/sails/service/base.rb

Overview

Like ActionController::Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.action_methodsObject


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sails/service/base.rb', line 13

def action_methods
  @action_methods ||= begin
    # All public instance methods of this class, including ancestors
    methods = (public_instance_methods(true) -
      # Except for public instance methods of Base and its ancestors
      internal_methods +
      # Be sure to include shadowed public instance methods of this class
      public_instance_methods(false)).uniq.map(&:to_s)

    # Clear out AS callback method pollution
    Set.new(methods.reject { |method| method =~ /_one_time_conditions/ })
  end
end

.internal_methodsObject


8
9
10
11
# File 'lib/sails/service/base.rb', line 8

def internal_methods
  controller = self.superclass
  controller.public_instance_methods(true)
end

Instance Method Details

#action_methodsObject


50
51
52
# File 'lib/sails/service/base.rb', line 50

def action_methods
  self.class.action_methods
end

#loggerObject

Sails.logger You can use this method in app/services


56
57
58
# File 'lib/sails/service/base.rb', line 56

def logger
  Sails.logger
end

#paramsObject

action params to Hash

example:

class FooService < Sails::Service::Base
   def foo(name, age)
     # you can use params in any instance methods
     puts params[:name]
     puts params[:age]
   end
end

40
41
42
# File 'lib/sails/service/base.rb', line 40

def params
  @params ||= {}
end

#raise_error(code, msg = nil) ⇒ Object

Raise a Sails::Service::Exception (Thrift::Exception) if you want custom error you can override this method in you ApplicationService

Raises:


46
47
48
# File 'lib/sails/service/base.rb', line 46

def raise_error(code, msg = nil)
  raise Exception.new(code: code, message: msg)
end