Class: Piggyback::Attribute
- Inherits:
-
Object
- Object
- Piggyback::Attribute
- Defined in:
- lib/piggyback.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
Instance Method Summary collapse
- #column ⇒ Object
-
#initialize(reflection, name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #select ⇒ Object
- #serialized_class ⇒ Object
Constructor Details
#initialize(reflection, name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/piggyback.rb', line 140 def initialize(reflection, name, = {}) @reflection = reflection @name = name.to_s if [:sql] @sql = Arel.sql([:sql]) @source = [:source].to_s if [:source] else @source = ([:source] || name).to_s end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
138 139 140 |
# File 'lib/piggyback.rb', line 138 def name @name end |
#reflection ⇒ Object (readonly)
Returns the value of attribute reflection.
138 139 140 |
# File 'lib/piggyback.rb', line 138 def reflection @reflection end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
138 139 140 |
# File 'lib/piggyback.rb', line 138 def source @source end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
138 139 140 |
# File 'lib/piggyback.rb', line 138 def sql @sql end |
Instance Method Details
#column ⇒ Object
164 165 166 |
# File 'lib/piggyback.rb', line 164 def column reflection.klass.columns_hash[source] end |
#select ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/piggyback.rb', line 151 def select unless defined? @select @select = if sql sql.as(Arel.sql(name)) elsif source == name reflection.klass.arel_table[name] else reflection.klass.arel_table[source].as(Arel.sql(name)) end end @select end |
#serialized_class ⇒ Object
168 169 170 |
# File 'lib/piggyback.rb', line 168 def serialized_class reflection.klass.serialized_attributes[source] end |