module BlockParty::Configuration::Conversion

Public Class Methods

included(base) click to toggle source
# File lib/block_party/configuration/conversion.rb, line 8
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

as_hash() click to toggle source

protected

# File lib/block_party/configuration/conversion.rb, line 66
def as_hash
  @__hash_representation__ ||= hash_representation
end
create_setter(setter) click to toggle source
# File lib/block_party/configuration/conversion.rb, line 89
def create_setter(setter)
  define_singleton_method setter do |value|
    invalidate_hash_representation!
    instance_variable_set :"@#{setter_to_getter(setter)}", value
  end
end
dump() click to toggle source
# File lib/block_party/configuration/conversion.rb, line 56
def dump
  to_hash.to_json.to_s
end
hash_representation() click to toggle source
# File lib/block_party/configuration/conversion.rb, line 70
def hash_representation
  unless empty?
    Hash[
      instance_variables.map do |instance_variable_name|
        key = instance_variable_name.to_s.gsub('@', '').to_sym
        value = instance_variable_get(instance_variable_name)
        value = value.hash_representation if value.is_a?(Configuration)
        [key, value]
      end
    ]
  else
    {}
  end
end
invalidate_hash_representation!() click to toggle source
# File lib/block_party/configuration/conversion.rb, line 85
def invalidate_hash_representation!
  @__hash_representation__ = nil
end
load_hash(source={}) click to toggle source
# File lib/block_party/configuration/conversion.rb, line 39
def load_hash(source={})
  source.each do |key, value|
    if value.is_a? Hash
      send :"#{key}=", self.class.from_hash(value)
    else
      send :"#{key}=", value
    end
  end
  self
end
to_hash() click to toggle source
# File lib/block_party/configuration/conversion.rb, line 50
def to_hash
  hash_representation.keep_if do |key|
    settings.include? key
  end
end
to_s() click to toggle source
# File lib/block_party/configuration/conversion.rb, line 60
def to_s
  to_hash.inspect.to_s
end