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



171
172
173
# File 'lib/active_fedora/reflection.rb', line 171

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.



141
142
143
# File 'lib/active_fedora/reflection.rb', line 141

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

#chainObject



175
176
177
# File 'lib/active_fedora/reflection.rb', line 175

def chain
  collect_join_chain
end

#check_validity_of_inverse!Object



163
164
165
166
167
168
169
# File 'lib/active_fedora/reflection.rb', line 163

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'



149
150
151
# File 'lib/active_fedora/reflection.rb', line 149

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

#constraintsObject



153
154
155
# File 'lib/active_fedora/reflection.rb', line 153

def constraints
  scope_chain.flatten
end

#inverse_ofObject



157
158
159
160
161
# File 'lib/active_fedora/reflection.rb', line 157

def inverse_of
  return unless inverse_name

  @inverse_of ||= klass._reflect_on_association inverse_name
end

#through_reflection?Boolean

:nodoc:

Returns:

  • (Boolean)


135
136
137
# File 'lib/active_fedora/reflection.rb', line 135

def through_reflection?
  false
end