Class: DatastaxRails::Reflection::MacroReflection

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

Overview

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

Direct Known Subclasses

AssociationReflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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


87
88
89
90
91
92
93
# File 'lib/datastax_rails/reflection.rb', line 87

def initialize(macro, name, options, datastax_rails)
  @macro           = macro
  @name            = name
  @options         = options
  @datastax_rails  = datastax_rails
  @plural_name     = name.to_s.pluralize
end

Instance Attribute Details

#datastax_railsObject (readonly)

Returns the value of attribute datastax_rails


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

def datastax_rails
  @datastax_rails
end

#denormsObject (readonly)

Returns a hash of all the denormalizations for this relationship (if any)


83
84
85
# File 'lib/datastax_rails/reflection.rb', line 83

def denorms
  @denorms
end

#macroObject (readonly)

Returns the macro type.

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


72
73
74
# File 'lib/datastax_rails/reflection.rb', line 72

def macro
  @macro
end

#nameObject (readonly)

Returns the name of the macro.

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


66
67
68
# File 'lib/datastax_rails/reflection.rb', line 66

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


78
79
80
# File 'lib/datastax_rails/reflection.rb', line 78

def options
  @options
end

#plural_nameObject (readonly)

:nodoc:


85
86
87
# File 'lib/datastax_rails/reflection.rb', line 85

def plural_name
  @plural_name
end

Instance Method Details

#==(other) ⇒ Object

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


113
114
115
116
117
118
119
# File 'lib/datastax_rails/reflection.rb', line 113

def ==(other)
  super ||
    other.is_a?(self.class) &&
      name == other.name &&
      other.options &&
      datastax_rails == other.datastax_rails
end

#class_nameObject

Returns the class name for the macro.

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


107
108
109
# File 'lib/datastax_rails/reflection.rb', line 107

def class_name
  @class_name ||= (options[:class_name] || derive_class_name).to_s
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


99
100
101
# File 'lib/datastax_rails/reflection.rb', line 99

def klass
  @klass ||= class_name.constantize
end

#sanitized_conditionsObject

XXX: Do we need to sanitize our query?


122
123
124
# File 'lib/datastax_rails/reflection.rb', line 122

def sanitized_conditions #:nodoc:
  @sanitized_conditions ||= options[:conditions]
end