Module: StandardService::Wrapper

Defined in:
lib/standard_service/wrapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/standard_service/wrapper.rb', line 3

def self.included(klass)
  class << klass
    def service(&block)
      define_method '_run', &block
    end

    def call(params = {})
      service = new(params)
      data = service._run

      StandardService::Result.new(data, service._conditions, service._meta)
    end
  end
end

Instance Method Details

#_conditionsObject



24
25
26
# File 'lib/standard_service/wrapper.rb', line 24

def _conditions
  @_conditions ||= {}
end

#_metaObject



28
29
30
# File 'lib/standard_service/wrapper.rb', line 28

def _meta
  @_meta ||= {}
end

#add_condition(type, desc = "") ⇒ Object



32
33
34
# File 'lib/standard_service/wrapper.rb', line 32

def add_condition(type, desc = "")
  _conditions[type.to_sym] = desc.to_s
end

#add_meta(type, desc = "") ⇒ Object



36
37
38
# File 'lib/standard_service/wrapper.rb', line 36

def add_meta(type, desc = "")
  _meta[type.to_sym] = desc.to_s
end

#initialize(params = {}) ⇒ Object



18
19
20
21
22
# File 'lib/standard_service/wrapper.rb', line 18

def initialize(params = {})
  params.to_h.each do |(name, value)|
    instance_variable_set("@#{name}", value)
  end
end