Class: ActiveRecord::Fusion::Association
- Inherits:
-
Object
- Object
- ActiveRecord::Fusion::Association
show all
- Defined in:
- lib/active_record/fusion.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(reflection, options = nil) ⇒ Association
Returns a new instance of Association.
89
90
91
92
93
|
# File 'lib/active_record/fusion.rb', line 89
def initialize(reflection, options = nil)
@reflection = reflection
@options = options.is_a?(Hash) ? options : { only: options }
@options.assert_valid_keys(:only, :except)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/active_record/fusion.rb', line 95
def method_missing(method, *args, &block)
if @reflection.respond_to? method
@reflection.send(method, *args, &block)
else
super
end
end
|
Instance Method Details
#attributes ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/active_record/fusion.rb', line 103
def attributes
unless @attributes
only = Array.wrap(@options[:only]).map(&:to_s)
except = Array.wrap(@options[:except]).map(&:to_s)
@attributes = klass.attribute_names
@attributes &= only if only.any?
@attributes -= active_record.attribute_names
@attributes -= [foreign_key] unless belongs_to?
@attributes -= except if except.any?
end
@attributes
end
|
#each_column ⇒ Object
117
118
119
120
121
|
# File 'lib/active_record/fusion.rb', line 117
def each_column
attributes.each do |name|
yield(name, klass.columns_hash[name], klass.serialized_attributes[name])
end
end
|
#joins ⇒ Object
127
128
129
130
|
# File 'lib/active_record/fusion.rb', line 127
def joins
dep = ActiveRecord::Associations::JoinDependency.new(active_record, name, [])
dep.join_associations.each{ |a| a.join_type = Arel::OuterJoin }
end
|
#selects ⇒ Object
123
124
125
|
# File 'lib/active_record/fusion.rb', line 123
def selects
@select ||= attributes.map{ |name| klass.arel_table[name] }
end
|