Class: ActiveFedora::Reflection::AbstractReflection

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

Overview

Holds all the methods that are shared between MacroReflection and ThroughReflection.

AbstractReflection
  MacroReflection
    AggregateReflection
    AssociationReflection
      HasManyReflection
      HasOneReflection
      BelongsToReflection
      HasAndBelongsToManyReflection
  ThroughReflection
    PolymorphicReflection
      RuntimeReflection

Direct Known Subclasses

MacroReflection

Instance Method Summary collapse

Instance Method Details

#alias_candidate(name) ⇒ Object



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

def alias_candidate(name)
  "#{plural_name}_#{name}"
end

#build_association(attributes, &block) ⇒ Object

Returns a new, unsaved instance of the associated class. attributes will be passed to the class’s constructor.



161
162
163
# File 'lib/active_fedora/reflection.rb', line 161

def build_association(attributes, &block)
  klass.new(attributes, &block)
end

#chainObject



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

def chain
  collect_join_chain
end

#check_validity_of_inverse!Object



183
184
185
186
187
188
189
# File 'lib/active_fedora/reflection.rb', line 183

def check_validity_of_inverse!
  unless polymorphic?
    if has_inverse? && inverse_of.nil?
      raise InverseOfAssociationNotFoundError, self
    end
  end
end

#class_nameObject

Returns the class name for the macro.

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



169
170
171
# File 'lib/active_fedora/reflection.rb', line 169

def class_name
  @class_name ||= (options[:class_name] || derive_class_name).to_s
end

#constraintsObject



173
174
175
# File 'lib/active_fedora/reflection.rb', line 173

def constraints
  scope_chain.flatten
end

#inverse_ofObject



177
178
179
180
181
# File 'lib/active_fedora/reflection.rb', line 177

def inverse_of
  return unless inverse_name

  @inverse_of ||= klass._reflect_on_association inverse_name
end

#through_reflection?Boolean

:nodoc:

Returns:

  • (Boolean)


155
156
157
# File 'lib/active_fedora/reflection.rb', line 155

def through_reflection?
  false
end