Class: Masterman::Reflection::Macro

Inherits:
Object
  • Object
show all
Defined in:
lib/masterman/reflection/macro.rb

Direct Known Subclasses

HasManyReflection, SinglurReflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, scope, options, model_class) ⇒ Macro

Returns a new instance of Macro.



6
7
8
9
10
11
# File 'lib/masterman/reflection/macro.rb', line 6

def initialize(name, scope, options, model_class)
  @name = name
  @scope = scope
  @options = options
  @model_class = model_class
end

Instance Attribute Details

#model_classObject (readonly)

Returns the value of attribute model_class.



4
5
6
# File 'lib/masterman/reflection/macro.rb', line 4

def model_class
  @model_class
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/masterman/reflection/macro.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/masterman/reflection/macro.rb', line 4

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/masterman/reflection/macro.rb', line 4

def scope
  @scope
end

Instance Method Details

#build_association(instance, reflection) ⇒ Object



21
22
23
# File 'lib/masterman/reflection/macro.rb', line 21

def build_association(instance, reflection)
  Masterman::Association.new(instance, reflection)
end

#collection?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/masterman/reflection/macro.rb', line 35

def collection?
  raise NotImplementedError, 'collection? is not defined'
end

#foreign_keyObject



13
14
15
# File 'lib/masterman/reflection/macro.rb', line 13

def foreign_key
  (options[:foreign_key] || "#{name.to_s}_id").to_s
end

#klassObject



25
26
27
# File 'lib/masterman/reflection/macro.rb', line 25

def klass
  @klass ||= compute_class(class_name)
end

#macroObject

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/masterman/reflection/macro.rb', line 17

def macro
  raise NotImplementedError, 'macro is not defined'
end

#through_reflectionObject



29
30
31
32
33
# File 'lib/masterman/reflection/macro.rb', line 29

def through_reflection
  if options[:through]
    model_class._reflections[options[:through].to_s]
  end
end