Class: RailsOr::WhereBindingMixs
- Inherits:
-
Object
- Object
- RailsOr::WhereBindingMixs
- Defined in:
- lib/rails_or/where_binding_mixs.rb
Instance Attribute Summary collapse
-
#bind_values ⇒ Object
readonly
Returns the value of attribute bind_values.
-
#where_values ⇒ Object
readonly
Returns the value of attribute where_values.
Instance Method Summary collapse
- #&(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
-
#initialize(where_values, bind_values) ⇒ WhereBindingMixs
constructor
A new instance of WhereBindingMixs.
- #select ⇒ Object
Constructor Details
#initialize(where_values, bind_values) ⇒ WhereBindingMixs
Returns a new instance of WhereBindingMixs.
5 6 7 8 |
# File 'lib/rails_or/where_binding_mixs.rb', line 5 def initialize(where_values, bind_values) @where_values = where_values @bind_values = bind_values end |
Instance Attribute Details
#bind_values ⇒ Object (readonly)
Returns the value of attribute bind_values.
3 4 5 |
# File 'lib/rails_or/where_binding_mixs.rb', line 3 def bind_values @bind_values end |
#where_values ⇒ Object (readonly)
Returns the value of attribute where_values.
2 3 4 |
# File 'lib/rails_or/where_binding_mixs.rb', line 2 def where_values @where_values end |
Instance Method Details
#&(other) ⇒ Object
18 19 20 21 |
# File 'lib/rails_or/where_binding_mixs.rb', line 18 def &(other) common_where_values = @where_values & other.where_values return select{|node| common_where_values.include?(node) } end |
#+(other) ⇒ Object
10 11 12 |
# File 'lib/rails_or/where_binding_mixs.rb', line 10 def +(other) self.class.new(@where_values + other.where_values, @bind_values + other.bind_values) end |
#-(other) ⇒ Object
14 15 16 |
# File 'lib/rails_or/where_binding_mixs.rb', line 14 def -(other) select{|node| !other.where_values.include?(node) } end |
#select ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rails_or/where_binding_mixs.rb', line 23 def select binds_index = 0 new_bind_values = [] new_where_values = @where_values.select do |node| flag = yield(node) if not node.is_a?(String) binds_contains = node.grep(Arel::Nodes::BindParam).size pre_binds_index = binds_index binds_index += binds_contains (pre_binds_index...binds_index).each{|i| new_bind_values << @bind_values[i] } if flag end next flag end return self.class.new(new_where_values, new_bind_values) end |