Class: ActiveFedora::Reflection::MacroReflection

Inherits:
AbstractReflection show all
Defined in:
lib/active_fedora/reflection.rb

Direct Known Subclasses

AssociationReflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractReflection

#alias_candidate, #build_association, #chain, #check_validity_of_inverse!, #class_name, #constraints, #inverse_of, #through_reflection?

Constructor Details

#initialize(macro, name, scope, options, active_fedora) ⇒ MacroReflection

Returns a new instance of MacroReflection.



200
201
202
203
204
205
206
207
208
# File 'lib/active_fedora/reflection.rb', line 200

def initialize(macro, name, scope, options, active_fedora)
  @macro = macro
  @name = name
  @scope = scope
  @options = options
  @active_fedora = active_fedora
  @klass         = options[:anonymous_class]
  @automatic_inverse_of = nil
end

Instance Attribute Details

#active_fedoraObject (readonly)

Returns the value of attribute active_fedora.



198
199
200
# File 'lib/active_fedora/reflection.rb', line 198

def active_fedora
  @active_fedora
end

#macroObject (readonly)

Returns the macro type.

has_many :clients returns :has_many



191
192
193
# File 'lib/active_fedora/reflection.rb', line 191

def macro
  @macro
end

#nameObject (readonly)

Returns the name of the macro.

has_many :clients returns :clients



184
185
186
# File 'lib/active_fedora/reflection.rb', line 184

def name
  @name
end

#optionsObject (readonly)

Returns the hash of options used for the macro.

has_many :clients returns {}



196
197
198
# File 'lib/active_fedora/reflection.rb', line 196

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



186
187
188
# File 'lib/active_fedora/reflection.rb', line 186

def scope
  @scope
end

Instance Method Details

#==(other) ⇒ Object

Returns true if self and other_aggregation have the same name attribute, active_record attribute, and other_aggregation has an options hash assigned to it.



230
231
232
233
234
235
236
# File 'lib/active_fedora/reflection.rb', line 230

def ==(other)
  super ||
    other.is_a?(self.class) &&
      name == other.name &&
      !other.options.nil? &&
      active_record == other.active_record
end

#autosave=(autosave) ⇒ Object



210
211
212
213
214
# File 'lib/active_fedora/reflection.rb', line 210

def autosave=(autosave)
  @options[:autosave] = autosave
  parent_reflection = self.parent_reflection
  parent_reflection.autosave = autosave if parent_reflection
end

#compute_class(name) ⇒ Object



224
225
226
# File 'lib/active_fedora/reflection.rb', line 224

def compute_class(name)
  name.constantize
end

#klassObject

Returns the class for the macro.

composed_of :balance, class_name: 'Money' returns the Money class has_many :clients returns the Client class



220
221
222
# File 'lib/active_fedora/reflection.rb', line 220

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