Module: ObjectAttorney::Representation::ClassMethods

Defined in:
lib/object_attorney/representation.rb

Instance Method Summary collapse

Instance Method Details

#represented_object_classObject



73
74
75
# File 'lib/object_attorney/representation.rb', line 73

def represented_object_class
  represented_object_reflection.try(:klass)
end

#represented_object_reflect_on_association(association) ⇒ Object



77
78
79
80
81
# File 'lib/object_attorney/representation.rb', line 77

def represented_object_reflect_on_association(association)
  return nil if represented_object_class.nil? || !represented_object_class.respond_to?(:reflect_on_association)

  represented_object_class.reflect_on_association(association)
end

#represented_object_reflectionObject



69
70
71
# File 'lib/object_attorney/representation.rb', line 69

def represented_object_reflection
  self.instance_variable_get("@represented_object_reflection") || zuper_method('represented_object_reflection')
end

#represents(represented_object_name, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/object_attorney/representation.rb', line 57

def represents(represented_object_name, options = {})
  self.instance_variable_set("@represented_object_reflection", Reflection.new(represented_object_name, options))

  define_method(represented_object_name) { represented_object }
  
  properties(*options[:properties]) if options.include?(:properties)
  getters(*options[:getters]) if options.include?(:getters)
  setters(*options[:setters]) if options.include?(:setters)

  class_eval { include Delegation::MissingMethods } if options[:delegate_missing_methods]
end