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(name, scope, options, active_fedora) ⇒ MacroReflection

Returns a new instance of MacroReflection.



217
218
219
220
221
222
223
224
# File 'lib/active_fedora/reflection.rb', line 217

def initialize(name, scope, options, active_fedora)
  @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.



215
216
217
# File 'lib/active_fedora/reflection.rb', line 215

def active_fedora
  @active_fedora
end

#nameObject (readonly)

Returns the name of the macro.

has_many :clients returns :clients



206
207
208
# File 'lib/active_fedora/reflection.rb', line 206

def name
  @name
end

#optionsObject (readonly)

Returns the hash of options used for the macro.

has_many :clients returns {}



213
214
215
# File 'lib/active_fedora/reflection.rb', line 213

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



208
209
210
# File 'lib/active_fedora/reflection.rb', line 208

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.



246
247
248
249
250
251
252
# File 'lib/active_fedora/reflection.rb', line 246

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

#autosave=(autosave) ⇒ Object



226
227
228
229
230
# File 'lib/active_fedora/reflection.rb', line 226

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

#compute_class(name) ⇒ Object



240
241
242
# File 'lib/active_fedora/reflection.rb', line 240

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



236
237
238
# File 'lib/active_fedora/reflection.rb', line 236

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