Class: ActiveNode::Reflection::MacroReflection

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

Overview

Base class for AggregateReflection and AssociationReflection. Objects of AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.

MacroReflection
  AggregateReflection
  AssociationReflection
    ThroughReflection

Direct Known Subclasses

AssociationReflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MacroReflection.



93
94
95
96
97
98
# File 'lib/active_node/reflection.rb', line 93

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

Instance Attribute Details

#macroObject (readonly)

Returns the macro type.

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



80
81
82
# File 'lib/active_node/reflection.rb', line 80

def macro
  @macro
end

#modelObject (readonly)

Returns the value of attribute model.



90
91
92
# File 'lib/active_node/reflection.rb', line 90

def model
  @model
end

#nameObject (readonly)

Returns the name of the macro.

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



74
75
76
# File 'lib/active_node/reflection.rb', line 74

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 {}



88
89
90
# File 'lib/active_node/reflection.rb', line 88

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



82
83
84
# File 'lib/active_node/reflection.rb', line 82

def scope
  @scope
end

Instance Method Details

#==(other_aggregation) ⇒ Object

Returns true if self and other_aggregation have the same name attribute, model attribute, and other_aggregation has an options hash assigned to it.



126
127
128
129
130
131
132
# File 'lib/active_node/reflection.rb', line 126

def ==(other_aggregation)
  super ||
      other_aggregation.kind_of?(self.class) &&
          name == other_aggregation.name &&
          other_aggregation.options &&
          model == other_aggregation.model
end

#class_nameObject

Returns the class name for the macro.

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



112
113
114
# File 'lib/active_node/reflection.rb', line 112

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

#directionObject



116
117
118
# File 'lib/active_node/reflection.rb', line 116

def direction
  @direction ||= (options[:direction] || :outgoing)
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



104
105
106
# File 'lib/active_node/reflection.rb', line 104

def klass
  @klass ||= class_name.constantize
end

#typeObject



120
121
122
# File 'lib/active_node/reflection.rb', line 120

def type
  @type ||= (options[:type] || derive_type)
end