Class: KBuilder::BaseConfiguration
- Inherits:
-
Object
- Object
- KBuilder::BaseConfiguration
- Defined in:
- lib/k_builder/base_configuration.rb
Overview
Base configuration object for all k_builder* GEM
Direct Known Subclasses
Class Method Summary collapse
-
.attach_config_to_parent(klass_child, klass_parent, accessor_name) ⇒ Object
(also: attach_to)
Attach a child configuration with it’s own settings to a parent configuration.
Instance Method Summary collapse
-
#basic_type?(value) ⇒ Boolean
This code is being moved into k_util (data) Any basic (aka primitive) type.
-
#complex_type?(value) ⇒ Boolean
Anything container that is not a regular class.
- #kv(name, value) ⇒ Object
-
#to_h ⇒ Object
move out into module.
Class Method Details
.attach_config_to_parent(klass_child, klass_parent, accessor_name) ⇒ Object Also known as: attach_to
Attach a child configuration with it’s own settings to a parent configuration
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/k_builder/base_configuration.rb', line 12 def attach_config_to_parent(klass_child, klass_parent, accessor_name) # Create a memoized getter to an instance of the attaching class (:klass_child) # # def third_party # @third_party ||= KBuilder::ThirdPartyGem::Configuration.new # end klass_parent.send(:define_method, accessor_name) do return instance_variable_get("@#{accessor_name}") if instance_variable_defined?("@#{accessor_name}") instance_variable_set("@#{accessor_name}", klass_child.new) end end |
Instance Method Details
#basic_type?(value) ⇒ Boolean
This code is being moved into k_util (data) Any basic (aka primitive) type
42 43 44 45 46 47 48 49 |
# File 'lib/k_builder/base_configuration.rb', line 42 def basic_type?(value) value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(FalseClass) || value.is_a?(TrueClass) || value.is_a?(Integer) || value.is_a?(Float) end |
#complex_type?(value) ⇒ Boolean
Anything container that is not a regular class
52 53 54 55 56 57 58 |
# File 'lib/k_builder/base_configuration.rb', line 52 def complex_type?(value) value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(Struct) || value.is_a?(OpenStruct) || value.respond_to?(:to_h) end |
#kv(name, value) ⇒ Object
60 61 62 |
# File 'lib/k_builder/base_configuration.rb', line 60 def kv(name, value) puts "#{name.rjust(30)} : #{value}" end |
#to_h ⇒ Object
move out into module
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/k_builder/base_configuration.rb', line 28 def to_h hash = {} instance_variables.each do |var| value = instance_variable_get(var) value = KUtil.data.to_hash(value) if complex_type?(value) hash[var.to_s.delete('@')] = value end hash end |