Module: Simple::Service
- Defined in:
- lib/simple/service.rb,
lib/simple/service.rb,
lib/simple/service/action.rb,
lib/simple/service/context.rb
Defined Under Namespace
Modules: ClassMethods
Classes: Action, ArgumentError, Context
Class Method Summary
collapse
Class Method Details
.context ⇒ Object
14
15
16
|
# File 'lib/simple/service.rb', line 14
def self.context
Thread.current[:"Simple::Service.context"]
end
|
.included(klass) ⇒ Object
10
11
12
|
# File 'lib/simple/service.rb', line 10
def self.included(klass)
klass.extend ClassMethods
end
|
.resolve(str) ⇒ Object
Resolves a service by name. Returns nil if the name does not refer to a service, or the service module otherwise.
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/simple/service.rb', line 53
def self.resolve(str)
return unless str =~ /^[A-Z][A-Za-z0-9_]*(::[A-Z][A-Za-z0-9_]*)*$/
service = resolve_constant(str)
return unless service.is_a?(Module)
return unless service.include?(::Simple::Service)
service
end
|
.resolve_constant(str) ⇒ Object
64
65
66
67
68
|
# File 'lib/simple/service.rb', line 64
def self.resolve_constant(str)
const_get(str)
rescue NameError
nil
end
|
.with_context(ctx) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/simple/service.rb', line 18
def self.with_context(ctx)
old_ctx = Thread.current[:"Simple::Service.context"]
Thread.current[:"Simple::Service.context"] = ctx
yield
ensure
Thread.current[:"Simple::Service.context"] = old_ctx
end
|