Class: SmqlToAR::Column
- Inherits:
-
Object
- Object
- SmqlToAR::Column
- Includes:
- Enumerable
- Defined in:
- lib/smql_to_ar.rb
Overview
Eine Spalte in einer Tabelle, relativ zu ‘Column#model`. Kann auch einen Pfad `Column#path` haben, wobei `Column#col` dann eine Relation von dem Model der letzten Relation von `Column#path` ist.
Defined Under Namespace
Classes: Col
Instance Attribute Summary collapse
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#model ⇒ Object
Returns the value of attribute model.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #allowed? ⇒ Boolean
- #child? ⇒ Boolean
- #each ⇒ Object
- #exist_in? ⇒ Boolean
-
#initialize(model, *col) ⇒ Column
constructor
A new instance of Column.
- #inspect ⇒ Object
- #joins(builder = nil, table = nil, &exe) ⇒ Object
- #last_model ⇒ Object
- #length ⇒ Object
- #protected? ⇒ Boolean
- #relation ⇒ Object
- #self? ⇒ Boolean
- #size ⇒ Object
- #to_a ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(model, *col) ⇒ Column
Returns a new instance of Column.
151 152 153 154 155 156 157 158 159 |
# File 'lib/smql_to_ar.rb', line 151 def initialize model, *col @model = model @last_model = nil *@path, @col = *Array.wrap( col). collect {|x| x.to_s.split /[.\/]/ }. flatten. collect( &Col.method( :new)). reject {|x| x === :self } end |
Instance Attribute Details
#col ⇒ Object (readonly)
Returns the value of attribute col.
119 120 121 |
# File 'lib/smql_to_ar.rb', line 119 def col @col end |
#model ⇒ Object
Returns the value of attribute model.
120 121 122 |
# File 'lib/smql_to_ar.rb', line 120 def model @model end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
119 120 121 |
# File 'lib/smql_to_ar.rb', line 119 def path @path end |
Instance Method Details
#allowed? ⇒ Boolean
213 |
# File 'lib/smql_to_ar.rb', line 213 def allowed?() ! self.protected? end |
#child? ⇒ Boolean
214 |
# File 'lib/smql_to_ar.rb', line 214 def child?() @path.empty? and !!relation end |
#each ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/smql_to_ar.rb', line 165 def each model = @model @path.each do |rel| unless rel === :self model = SmqlToAR.model_of model, rel return false unless model yield rel, model end end model end |
#exist_in? ⇒ Boolean
177 178 179 180 181 |
# File 'lib/smql_to_ar.rb', line 177 def exist_in? model = last_model return false unless model model.column_names.include? @col.to_s end |
#inspect ⇒ Object
211 |
# File 'lib/smql_to_ar.rb', line 211 def inspect() "#<Column: #{model} #{to_s}>" end |
#joins(builder = nil, table = nil, &exe) ⇒ Object
194 195 196 197 198 199 200 201 202 |
# File 'lib/smql_to_ar.rb', line 194 def joins builder = nil, table = nil, &exe pp = [] table = Array.wrap table exe ||= builder ? lambda {|j, m| builder.joins table+j, m} : Array.method( :[]) collect do |rel, model| pp.push rel exe.call pp, model end end |
#last_model ⇒ Object
161 162 163 |
# File 'lib/smql_to_ar.rb', line 161 def last_model @last_model ||= each{} end |
#length ⇒ Object
205 |
# File 'lib/smql_to_ar.rb', line 205 def length() @path.length+(self.self? ? 0 : 1) end |
#protected? ⇒ Boolean
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/smql_to_ar.rb', line 183 def protected? model = @model each do |rel, _model| pr = Array.wrap model.respond_to?( :smql_protected) ? model.smql_protected : nil pr.include? rel.to_s model = _model end pr = Array.wrap model.respond_to?( :smql_protected) ? model.smql_protected : nil pr.include? @col.to_s end |
#relation ⇒ Object
212 |
# File 'lib/smql_to_ar.rb', line 212 def relation() self.self? ? model : SmqlToAR.model_of( last_model, @col) end |
#self? ⇒ Boolean
204 |
# File 'lib/smql_to_ar.rb', line 204 def self?() !@col end |
#size ⇒ Object
206 |
# File 'lib/smql_to_ar.rb', line 206 def size() @path.size+(self.self? ? 0 : 1) end |
#to_a ⇒ Object
207 |
# File 'lib/smql_to_ar.rb', line 207 def to_a() @path+(self.self? ? [] : [@col]) end |
#to_json ⇒ Object
210 |
# File 'lib/smql_to_ar.rb', line 210 def to_json() to_s end |
#to_s ⇒ Object
208 |
# File 'lib/smql_to_ar.rb', line 208 def to_s() to_a.join '.' end |
#to_sym ⇒ Object
209 |
# File 'lib/smql_to_ar.rb', line 209 def to_sym() to_s.to_sym end |