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)
-
- (Object) name
readonly
Returns the name of the macro.
-
- (Object) options
readonly
Returns the hash of options used for the macro.
Instance Method Summary (collapse)
-
- (Object) build_association(*options)
Returns a new, unsaved instance of the associated class.
-
- (Object) class_name
Returns the class name for the macro.
-
- (Boolean) collection?
Returns whether or not this association reflection is for a collection association.
-
- (MacroReflection) initialize(macro, name, options, active_fedora)
constructor
A new instance of MacroReflection.
-
- (Object) klass
Returns the class for the macro.
Constructor Details
- (MacroReflection) initialize(macro, name, options, active_fedora)
A new instance of MacroReflection
64 65 66 |
# File 'lib/active_fedora/reflection.rb', line 64 def initialize(macro, name, , active_fedora) @macro, @name, @options, @active_fedora = macro, name, , active_fedora end |
Instance Attribute Details
- (Object) name (readonly)
Returns the name of the macro.
composed_of :balance, :class_name => 'Money' returns :balance has_many :clients returns :clients
78 79 80 |
# File 'lib/active_fedora/reflection.rb', line 78 def name @name end |
- (Object) options (readonly)
Returns the hash of options used for the macro.
composed_of :balance, :class_name => 'Money' returns { :class_name => "Money" } has_many :clients returns {}
85 86 87 |
# File 'lib/active_fedora/reflection.rb', line 85 def @options end |
Instance Method Details
- (Object) build_association(*options)
Returns a new, unsaved instance of the associated class. options will be passed to the class's constructor.
70 71 72 |
# File 'lib/active_fedora/reflection.rb', line 70 def build_association(*) klass.new(*) end |
- (Object) class_name
Returns the class name for the macro.
composed_of :balance, :class_name => 'Money' returns 'Money' has_many :clients returns 'Client'
100 101 102 |
# File 'lib/active_fedora/reflection.rb', line 100 def class_name @class_name ||= [:class_name] || derive_class_name end |
- (Boolean) collection?
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.
108 109 110 |
# File 'lib/active_fedora/reflection.rb', line 108 def collection? @collection end |
- (Object) klass
Returns the class for the macro.
composed_of :balance, :class_name => 'Money' returns the Money class has_many :clients returns the Client class
57 58 59 60 |
# File 'lib/active_fedora/reflection.rb', line 57 def klass #@klass ||= active_record.send(:compute_type, class_name) @klass ||= class_name end |