module Composition::Macros::Compose

Public Instance Methods

method_missing(method_name, *args, &block) click to toggle source
Calls superclass method
# File lib/composition/macros/compose.rb, line 6
def method_missing(method_name, *args, &block)
  if match_composition?(method_name)
    Composition::Builders::Compose.new(self).def_composition_methods
    send(method_name, *args, &block)
  else
    super
  end
end
respond_to?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/composition/macros/compose.rb, line 15
def respond_to?(method_name, include_private = false)
  if match_composition?(method_name)
    Composition::Builders::Compose.new(self).def_composition_methods
    true
  else
    super
  end
end

Private Instance Methods

compose(*args) click to toggle source
# File lib/composition/macros/compose.rb, line 32
def compose(*args)
  composed_attribute = args.shift
  options = args.last || {}
  options = {
    composed_attribute: composed_attribute,
    mapping: options[:mapping],
    class_name: options[:class_name] || composed_attribute.to_s.camelize,
    inverse_of: options[:inverse_of] || model_name.name
  }
  composition = Compositions::Compose.new(options[:composed_attribute], options)
  add_composition_reflection(self, options[:class_name], composition)
end
match_composition?(method_id) click to toggle source
# File lib/composition/macros/compose.rb, line 26
def match_composition?(method_id)
  composition_name = method_id.to_s.gsub(/=$/, '')
  _composition_reflections.any? { |_, composition| composition_name == composition.name.to_s }
end