Module: Confo

Defined in:
lib/confo.rb,
lib/confo/config.rb,
lib/confo/version.rb,
lib/confo/collection.rb,
lib/confo/preconfigurator.rb,
lib/confo/concerns/options_manager.rb,
lib/confo/concerns/subconfigs_manager.rb

Defined Under Namespace

Modules: OptionsManager, SubconfigsManager Classes: Collection, Config, OptionsStorage, Preconfigurator, PreconfiguratorNotImplementedError

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.call_method_with_floating_arguments(object, method, *args) ⇒ Object Also known as: call



34
35
36
37
38
39
# File 'lib/confo.rb', line 34

def call_method_with_floating_arguments(object, method, *args)
  callable      = object.method(method)
  arity         = callable.arity
  resized_args  = arity < 0 ? args : args[0...arity]
  callable.call(*resized_args)
end

.callable_without_arguments?(obj) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/confo.rb', line 20

def callable_without_arguments?(obj)
  obj.respond_to?(:call) && (!obj.respond_to?(:arity) || obj.arity == 0)
end

.convert_to_hash(value) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/confo.rb', line 24

def convert_to_hash(value)
  if value.is_a?(Hash)
    value.to_hash
  elsif value.is_a?(Array)
    value.map { |e| convert_to_hash(e) }
  else
    value.respond_to?(:to_hash) ? value.to_hash : value
  end
end

.result_of(value, *args) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/confo.rb', line 11

def result_of(value, *args)
  if value.respond_to?(:call)
    _args_ = value.arity < 0 ? args : args[0...value.arity]
    value.call(*args)
  else
    value
  end
end