module Habuco
Constants
- VERSION
Attributes
context[R]
Public Class Methods
included(base)
click to toggle source
# File lib/habuco.rb, line 41 def self.included(base) base.extend(ClassMethods) end
new(context = {})
click to toggle source
# File lib/habuco.rb, line 47 def initialize(context = {}) @context = OpenStruct.new(context) end
Public Instance Methods
build()
click to toggle source
# File lib/habuco.rb, line 51 def build {}.tap do |data| perform_each_definitions perform_attribute_definitions(data) end end
Private Instance Methods
perform_attribute_definitions(data)
click to toggle source
# File lib/habuco.rb, line 68 def perform_attribute_definitions(data) self.class.attribute_definitions.each do |key, definition| val = definition.value d = definition.namespace.inject(data) { |h, k| h[k] ||= {} } k = key.respond_to?(:call) ? context.instance_exec(&key) : key d[k] = val.respond_to?(:call) ? context.instance_exec(&val) : val end end
perform_each_definitions()
click to toggle source
# File lib/habuco.rb, line 60 def perform_each_definitions self.class.each_definitions.each do |_key, definition| values = definition.values block = definition.block context.instance_exec(&values).each_with_index(&block) end end