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.
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
- #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
- #protected? ⇒ Boolean
- #relation ⇒ 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.
103 104 105 106 107 |
# File 'lib/smql_to_ar.rb', line 103 def initialize model, *col @model = model @last_model = nil *@path, @col = Array.wrap( col).collect {|s| s.to_s.split /[.\/]/ }.flatten.collect &:to_sym end |
Instance Attribute Details
#col ⇒ Object (readonly)
Returns the value of attribute col.
100 101 102 |
# File 'lib/smql_to_ar.rb', line 100 def col @col end |
#model ⇒ Object
Returns the value of attribute model.
101 102 103 |
# File 'lib/smql_to_ar.rb', line 101 def model @model end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
100 101 102 |
# File 'lib/smql_to_ar.rb', line 100 def path @path end |
Instance Method Details
#allowed? ⇒ Boolean
155 |
# File 'lib/smql_to_ar.rb', line 155 def allowed?() ! self.protected? end |
#each ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/smql_to_ar.rb', line 113 def each model = @model @path.each do |rel| model = SmqlToAR.model_of model, rel return false unless model yield rel, model end model end |
#exist_in? ⇒ Boolean
123 124 125 126 127 |
# File 'lib/smql_to_ar.rb', line 123 def exist_in? model = last_model return false unless model model.column_names.include? @col.to_s end |
#inspect ⇒ Object
153 |
# File 'lib/smql_to_ar.rb', line 153 def inspect() "#<Column: #{model} #{to_s}>" end |
#joins(builder = nil, table = nil, &exe) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/smql_to_ar.rb', line 140 def joins builder = nil, table = nil, &exe pp = [] table = Array.wrap table exe ||= builder ? lambda {|j, m| builder.join table+j, m} : Array.method( :[]) collect do |rel, model| pp.push rel exe.call pp, model end end |
#last_model ⇒ Object
109 110 111 |
# File 'lib/smql_to_ar.rb', line 109 def last_model @last_model ||= each{} end |
#protected? ⇒ Boolean
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/smql_to_ar.rb', line 129 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
154 |
# File 'lib/smql_to_ar.rb', line 154 def relation() SmqlToAR.model_of last_model, @col end |
#to_a ⇒ Object
149 |
# File 'lib/smql_to_ar.rb', line 149 def to_a() @path+[@col] end |
#to_json ⇒ Object
152 |
# File 'lib/smql_to_ar.rb', line 152 def to_json() to_s end |
#to_s ⇒ Object
150 |
# File 'lib/smql_to_ar.rb', line 150 def to_s() to_a.join '.' end |
#to_sym ⇒ Object
151 |
# File 'lib/smql_to_ar.rb', line 151 def to_sym() to_s.to_sym end |