Class: ActiveFedora::Reflection::ClassMethods::MacroReflection
- Inherits:
-
Object
- Object
- ActiveFedora::Reflection::ClassMethods::MacroReflection
- Defined in:
- lib/active_fedora/reflection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#macro ⇒ Object
readonly
Returns the value of attribute macro.
-
#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
-
#build_association(*options) ⇒ 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.
-
#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.
65 66 67 |
# File 'lib/active_fedora/reflection.rb', line 65 def initialize(macro, name, , active_fedora) @macro, @name, @options, @active_fedora = macro, name, , active_fedora end |
Instance Attribute Details
#macro ⇒ Object (readonly)
Returns the value of attribute macro.
85 86 87 |
# File 'lib/active_fedora/reflection.rb', line 85 def macro @macro end |
#name ⇒ Object (readonly)
Returns the name of the macro.
has_many :clients
returns :clients
78 79 80 |
# File 'lib/active_fedora/reflection.rb', line 78 def name @name end |
#options ⇒ Object (readonly)
Returns the hash of options used for the macro.
has_many :clients
returns {}
83 84 85 |
# File 'lib/active_fedora/reflection.rb', line 83 def @options end |
Instance Method Details
#build_association(*options) ⇒ Object
Returns a new, unsaved instance of the associated class. options
will be passed to the class’s constructor.
71 72 73 |
# File 'lib/active_fedora/reflection.rb', line 71 def build_association(*) klass.new(*) end |
#class_name ⇒ Object
Returns the class name for the macro.
has_many :clients
returns 'Client'
90 91 92 |
# File 'lib/active_fedora/reflection.rb', line 90 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.
97 98 99 |
# File 'lib/active_fedora/reflection.rb', line 97 def collection? @collection 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.
61 62 63 |
# File 'lib/active_fedora/reflection.rb', line 61 def klass @klass ||= class_name.constantize end |