Class: Nexter::Derange
- Inherits:
-
Object
- Object
- Nexter::Derange
- Defined in:
- lib/nexter/derange.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#compass ⇒ Object
readonly
Returns the value of attribute compass.
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#reorder ⇒ Object
readonly
Returns the value of attribute reorder.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
-
#trunks ⇒ Object
Returns the value of attribute trunks.
Instance Method Summary collapse
-
#initialize(model, goto) ⇒ Derange
constructor
A new instance of Derange.
- #range ⇒ Object
- #set_vals(order_vals, order_col) ⇒ Object
- #slice ⇒ Object
- #value_of(cursor) ⇒ Object
- #where ⇒ Object
Constructor Details
#initialize(model, goto) ⇒ Derange
Returns a new instance of Derange.
11 12 13 14 15 16 17 18 |
# File 'lib/nexter/derange.rb', line 11 def initialize(model, goto) @model = model @table_name = model.class.table_name @trunks = [] @reorder = false @or_null = false @compass = Nexter::Compass.new(goto) end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
6 7 8 |
# File 'lib/nexter/derange.rb', line 6 def columns @columns end |
#compass ⇒ Object (readonly)
Returns the value of attribute compass.
4 5 6 |
# File 'lib/nexter/derange.rb', line 4 def compass @compass end |
#delimiter ⇒ Object
Returns the value of attribute delimiter.
6 7 8 |
# File 'lib/nexter/derange.rb', line 6 def delimiter @delimiter end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/nexter/derange.rb', line 4 def model @model end |
#reorder ⇒ Object (readonly)
Returns the value of attribute reorder.
4 5 6 |
# File 'lib/nexter/derange.rb', line 4 def reorder @reorder end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
4 5 6 |
# File 'lib/nexter/derange.rb', line 4 def table_name @table_name end |
#trunks ⇒ Object
Returns the value of attribute trunks.
6 7 8 |
# File 'lib/nexter/derange.rb', line 6 def trunks @trunks end |
Instance Method Details
#range ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nexter/derange.rb', line 34 def range trunk = columns.map do |col| if range_value = value_of(col[0]) # binding.pry "#{col[0]} = #{model.class.sanitize range_value}" else "#{col[0]} IS NULL" end end.join(' AND ') end |
#set_vals(order_vals, order_col) ⇒ Object
20 21 22 23 24 |
# File 'lib/nexter/derange.rb', line 20 def set_vals(order_vals, order_col) @columns = order_vals @delimiter = order_col[0] compass.direction = order_col[1] end |
#slice ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/nexter/derange.rb', line 45 def slice if val = value_of(delimiter) d = model.class.sanitize val delimited = "#{delimiter} #{bracket} #{d}" else # @reorder = true "#{delimiter} IS NULL AND #{table_name}.id > #{model.id}" end end |
#value_of(cursor) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nexter/derange.rb', line 55 def value_of(cursor) splits = cursor.split(".") result = if splits.first == table_name || splits.size == 1 model.send(splits.last) else # binding.pry asso = model.class.reflections.keys.grep(/#{splits.first.singularize}/).first asso = model.send(asso) and asso.send(splits.last) end end |
#where ⇒ Object
26 27 28 |
# File 'lib/nexter/derange.rb', line 26 def where "(#{range} #{range.blank? ? '' : 'AND'} #{slice})" end |