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



11
12
13
14
15
16
17
18
19
20
# File 'lib/kiba/extend/registry/creator.rb', line 11

def initialize(spec)
  @spec = spec.is_a?(Proc) ? spec.call : spec
  if Kiba::Extend.job_verbosity == :debug
    puts "Initializing Creator class for #{@spec}"
  end
  @mod = nil
  @meth = nil
  @args = nil
  set_vars
end

Instance Attribute Details

#argsObject (readonly)

Since:

  • 2.2.0



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

def args
  @args
end

#methObject (readonly)

Since:

  • 2.2.0



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

def meth
  @meth
end

#modObject (readonly)

Since:

  • 2.2.0



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

def mod
  @mod
end

Instance Method Details

#callObject

Since:

  • 2.2.0



22
23
24
25
26
27
28
# File 'lib/kiba/extend/registry/creator.rb', line 22

def call
  if args
    mod.send(meth, **args)
  else
    mod.send(meth)
  end
end

#to_sObject

Since:

  • 2.2.0



30
31
32
33
34
35
36
37
# File 'lib/kiba/extend/registry/creator.rb', line 30

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