Class: ActiveFedora::Reflection::MacroReflection
- Inherits:
-
Object
- Object
- ActiveFedora::Reflection::MacroReflection
- Defined in:
- lib/active_fedora/reflection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#active_fedora ⇒ Object
readonly
Returns the value of attribute active_fedora.
-
#macro ⇒ Object
readonly
Returns the macro type.
-
#name ⇒ Object
readonly
Returns the name of the macro.
-
#options ⇒ Object
readonly
Returns the hash of options used for the macro.
Instance Method Summary collapse
-
#belongs_to? ⇒ Boolean
Returns
true
ifself
is abelongs_to
reflection. -
#build_association(*options, &block) ⇒ Object
Returns a new, unsaved instance of the associated class.
-
#class_name ⇒ Object
Returns the class name for the macro.
-
#collection? ⇒ Boolean
Returns whether or not this association reflection is for a collection association.
- #has_and_belongs_to_many? ⇒ Boolean
- #has_many? ⇒ Boolean
-
#initialize(macro, name, options, active_fedora) ⇒ MacroReflection
constructor
A new instance of MacroReflection.
-
#klass ⇒ Object
Returns the target association’s class.
Constructor Details
#initialize(macro, name, options, active_fedora) ⇒ MacroReflection
Returns a new instance of MacroReflection.
105 106 107 108 109 110 111 |
# File 'lib/active_fedora/reflection.rb', line 105 def initialize(macro, name, , active_fedora) @macro = macro @name = name @options = @active_fedora = active_fedora @automatic_inverse_of = nil end |
Instance Attribute Details
#active_fedora ⇒ Object (readonly)
Returns the value of attribute active_fedora.
87 88 89 |
# File 'lib/active_fedora/reflection.rb', line 87 def active_fedora @active_fedora end |
#macro ⇒ Object (readonly)
Returns the macro type.
has_many :clients
returns :has_many
80 81 82 |
# File 'lib/active_fedora/reflection.rb', line 80 def macro @macro end |
#name ⇒ Object (readonly)
Returns the name of the macro.
has_many :clients
returns :clients
75 76 77 |
# File 'lib/active_fedora/reflection.rb', line 75 def name @name end |
#options ⇒ Object (readonly)
Returns the hash of options used for the macro.
has_many :clients
returns {}
85 86 87 |
# File 'lib/active_fedora/reflection.rb', line 85 def @options end |
Instance Method Details
#belongs_to? ⇒ Boolean
Returns true
if self
is a belongs_to
reflection.
134 135 136 |
# File 'lib/active_fedora/reflection.rb', line 134 def belongs_to? macro == :belongs_to end |
#build_association(*options, &block) ⇒ Object
Returns a new, unsaved instance of the associated class. options
will be passed to the class’s constructor.
115 116 117 |
# File 'lib/active_fedora/reflection.rb', line 115 def build_association(*, &block) klass.new(*, &block) end |
#class_name ⇒ Object
Returns the class name for the macro.
has_many :clients
returns 'Client'
122 123 124 |
# File 'lib/active_fedora/reflection.rb', line 122 def class_name @class_name ||= [:class_name] || derive_class_name end |
#collection? ⇒ Boolean
Returns whether or not this association reflection is for a collection association. Returns true
if the macro
is either has_many
or has_and_belongs_to_many
, false
otherwise.
129 130 131 |
# File 'lib/active_fedora/reflection.rb', line 129 def collection? @collection end |
#has_and_belongs_to_many? ⇒ Boolean
142 143 144 |
# File 'lib/active_fedora/reflection.rb', line 142 def has_and_belongs_to_many? macro == :has_and_belongs_to_many end |
#has_many? ⇒ Boolean
138 139 140 |
# File 'lib/active_fedora/reflection.rb', line 138 def has_many? macro == :has_many end |
#klass ⇒ Object
Returns the target association’s class.
class Author < ActiveRecord::Base
has_many :books
end
Author.reflect_on_association(:books).klass
# => Book
Note: Do not call klass.new
or klass.create
to instantiate a new association object. Use build_association
or create_association
instead. This allows plugins to hook into association object creation.
101 102 103 |
# File 'lib/active_fedora/reflection.rb', line 101 def klass @klass ||= class_name.constantize end |