Class: ActiveFedora::Reflection::ClassMethods::MacroReflection

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

Direct Known Subclasses

AssociationReflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(macro, name, options, active_fedora) ⇒ MacroReflection

Returns a new instance of MacroReflection.



56
57
58
# File 'lib/active_fedora/reflection.rb', line 56

def initialize(macro, name, options, active_fedora)
  @macro, @name, @options, @active_fedora = macro, name, options, active_fedora
end

Instance Attribute Details

#nameObject (readonly)

Returns the name of the macro.

composed_of :balance, :class_name => 'Money' returns :balance has_many :clients returns :clients



70
71
72
# File 'lib/active_fedora/reflection.rb', line 70

def name
  @name
end

#optionsObject (readonly)

Returns the hash of options used for the macro.

composed_of :balance, :class_name => 'Money' returns { :class_name => "Money" } has_many :clients returns {}



77
78
79
# File 'lib/active_fedora/reflection.rb', line 77

def options
  @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.



62
63
64
# File 'lib/active_fedora/reflection.rb', line 62

def build_association(*options)
  klass.new(*options)
end

#class_nameObject

Returns the class name for the macro.

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



92
93
94
# File 'lib/active_fedora/reflection.rb', line 92

def class_name
  @class_name ||= options[: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.

Returns:

  • (Boolean)


100
101
102
# File 'lib/active_fedora/reflection.rb', line 100

def collection?
  @collection
end

#klassObject

Returns the class for the macro.

composed_of :balance, :class_name => 'Money' returns the Money class has_many :clients returns the Client class



49
50
51
52
# File 'lib/active_fedora/reflection.rb', line 49

def klass
  #@klass ||= active_record.send(:compute_type, class_name)
  @klass ||= class_name
end