Class: Merge::Base::Association
- Inherits:
-
Object
- Object
- Merge::Base::Association
show all
- Defined in:
- lib/merge/base.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(reflection, options = nil) ⇒ Association
Returns a new instance of Association.
80
81
82
83
84
|
# File 'lib/merge/base.rb', line 80
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
86
87
88
89
90
91
92
|
# File 'lib/merge/base.rb', line 86
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
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/merge/base.rb', line 94
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
108
109
110
111
112
|
# File 'lib/merge/base.rb', line 108
def each_column
attributes.each do |name|
yield(name, klass.columns_hash[name], klass.serialized_attributes[name])
end
end
|
#selects ⇒ Object
114
115
116
|
# File 'lib/merge/base.rb', line 114
def selects
@select ||= attributes.map{ |name| klass.arel_table[name] }
end
|