Class: Kiba::Extend::Registry::Creator
- Inherits:
-
Object
- Object
- Kiba::Extend::Registry::Creator
show all
- Defined in:
- lib/kiba/extend/registry/creator.rb,
lib/kiba/extend/registry/creator/type_error.rb,
lib/kiba/extend/registry/creator/hash_creator_key_error.rb,
lib/kiba/extend/registry/creator/hash_creator_callee_error.rb,
lib/kiba/extend/registry/creator/hash_creator_args_type_error.rb,
lib/kiba/extend/registry/creator/jobless_module_creator_error.rb
Overview
Bundles up the logic/options of different ways of validating and calling registry entry creators
Defined Under Namespace
Classes: HashCreatorArgsTypeError, HashCreatorCalleeError, HashCreatorKeyError, JoblessModuleCreatorError, TypeError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(spec) ⇒ Creator
Returns a new instance of Creator.
12
13
14
15
16
17
18
|
# File 'lib/kiba/extend/registry/creator.rb', line 12
def initialize(spec)
@spec = spec.is_a?(Proc) ? spec.call : spec
@mod = nil
@meth = nil
@args = nil
set_vars
end
|
Instance Attribute Details
#args ⇒ Object
10
11
12
|
# File 'lib/kiba/extend/registry/creator.rb', line 10
def args
@args
end
|
#meth ⇒ Object
10
11
12
|
# File 'lib/kiba/extend/registry/creator.rb', line 10
def meth
@meth
end
|
#mod ⇒ Object
10
11
12
|
# File 'lib/kiba/extend/registry/creator.rb', line 10
def mod
@mod
end
|
Instance Method Details
#call ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/kiba/extend/registry/creator.rb', line 20
def call
if args
mod.send(meth, **args)
else
mod.send(meth)
end
end
|
#to_s ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/kiba/extend/registry/creator.rb', line 28
def to_s
mod_meth = "#{mod}.#{meth}"
return mod_meth unless args
arg_str = args.map { |key, val| "#{key}: #{val}" }
.join(", ")
"#{mod_meth}(#{arg_str})"
end
|