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

Returns a new instance of MacroReflection.



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

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.



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

def datastax_rails
  @datastax_rails
end

#denormsObject (readonly)

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



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

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



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

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



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

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/datastax_rails/reflection.rb', line 77

def options
  @options
end

#plural_nameObject (readonly)

:nodoc:



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

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.



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

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'



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

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



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

def klass
  @klass ||= class_name.constantize
end

#sanitized_conditionsObject

XXX: Do we need to sanitize our query?



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

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