Class: Kiba::Extend::Registry::Creator

Inherits:
Object
  • Object
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

Since:

  • 2.2.0

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.

Since:

  • 2.2.0



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

#argsObject (readonly)

Since:

  • 2.2.0



10
11
12
# File 'lib/kiba/extend/registry/creator.rb', line 10

def args
  @args
end

#methObject (readonly)

Since:

  • 2.2.0



10
11
12
# File 'lib/kiba/extend/registry/creator.rb', line 10

def meth
  @meth
end

#modObject (readonly)

Since:

  • 2.2.0



10
11
12
# File 'lib/kiba/extend/registry/creator.rb', line 10

def mod
  @mod
end

Instance Method Details

#callObject

Since:

  • 2.2.0



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_sObject

Since:

  • 2.2.0



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