sunstone 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 932214114f8eca2aa1070795e17fd2c1e2cdf129
4
- data.tar.gz: 752db701091fb743681348f1b9a34e1f4bcf1e2f
3
+ metadata.gz: f5b03328d14a617316bc09421b97d94726aa85e6
4
+ data.tar.gz: a46d7b00f94e8a052d6014ab391bdf153c1686fd
5
5
  SHA512:
6
- metadata.gz: 4551d1399d76ce59806fcc33ed50267142247e22d321b814fe2216b8e8398809769305af7f1689ee0f2b93cd01caa403a74d7765662d9277ba77c35b10d8ba4c
7
- data.tar.gz: a93c30a197f5e0d8d8538bf80576bd84fd4422ca4a694adb3c1d6d135b33d7cf4173f4c56a333d93c0ef91bc7dc462a6ce2608e5ad8b42dd238de85484ae8a91
6
+ metadata.gz: d82113de48120d57a36fa5cd35b980bac4456671c81c4712547d9323fbb4d620525a76271de2cfc9f4c4eea60934032510e5cb7f902fac8124261515ac31831c
7
+ data.tar.gz: 788d96dfeda86bee15c0b2009a3f05ba5838791a98354567af7040c1dee24690804559c6a4c18a22443e05048738722f5cbec74b58c10af13345dd820f2a82fc
@@ -2,7 +2,7 @@ module Arel
2
2
  module Collectors
3
3
  class Sunstone < Arel::Collectors::Bind
4
4
 
5
- attr_accessor :request_type, :table, :where, :limit, :offset, :order, :operation, :columns, :updates, :eager_loads
5
+ attr_accessor :request_type, :table, :where, :limit, :offset, :order, :operation, :columns, :updates, :eager_loads, :id
6
6
 
7
7
  def substitute_binds hash, bvs
8
8
  if hash.is_a?(Array)
@@ -42,6 +42,8 @@ module Arel
42
42
  case operation
43
43
  when :count, :average, :min, :max
44
44
  path += "/#{operation}"
45
+ when :update
46
+ path += "/#{id}"
45
47
  end
46
48
 
47
49
  get_params = {}
@@ -109,27 +109,26 @@ module Arel
109
109
  # stmt
110
110
  # end
111
111
  #
112
- # def visit_Arel_Nodes_UpdateStatement o, collector
113
- # if o.orders.empty? && o.limit.nil?
114
- # wheres = o.wheres
115
- # else
116
- # wheres = [Nodes::In.new(o.key, [build_subselect(o.key, o)])]
117
- # end
118
- #
119
- # collector << "UPDATE "
120
- # collector = visit o.relation, collector
121
- # unless o.values.empty?
122
- # collector << " SET "
123
- # collector = inject_join o.values, collector, ", "
124
- # end
125
- #
126
- # unless wheres.empty?
127
- # collector << " WHERE "
128
- # collector = inject_join wheres, collector, " AND "
129
- # end
130
- #
131
- # collector
132
- # end
112
+ def visit_Arel_Nodes_UpdateStatement o, collector
113
+ collector.request_type = Net::HTTP::Patch
114
+ collector.table = o.relation.name
115
+ collector.operation = :update
116
+
117
+ wheres = o.wheres.map { |x| visit(x, collector) }.inject([]) { |c, w|
118
+ w.is_a?(Array) ? c += w : c << w
119
+ }
120
+ if wheres.size != 1 && wheres.first.size != 1 && !wheres['id']
121
+ raise 'Upsupported'
122
+ end
123
+
124
+ collector.id = wheres.first['id']
125
+
126
+ if o.values
127
+ collector.updates = o.values.map { |x| visit(x, collector) }.inject({}){|c,v| c.merge(v) }#.zip(o.values).to_h
128
+ end
129
+
130
+ collector
131
+ end
133
132
  #
134
133
  #
135
134
  # def visit_Arel_Nodes_Exists o, collector
@@ -392,7 +391,7 @@ module Arel
392
391
  #
393
392
  def visit_Arel_Nodes_Count o, collector
394
393
  collector.operation = :count
395
- collector.columns = o.expressions.first
394
+ collector.columns = visit o.expressions.first, collector
396
395
  end
397
396
  #
398
397
  # def visit_Arel_Nodes_Sum o, collector
@@ -590,18 +589,16 @@ module Arel
590
589
  ors
591
590
  end
592
591
 
593
- # def visit_Arel_Nodes_Assignment o, collector
594
- # case o.right
595
- # when Arel::Nodes::UnqualifiedColumn, Arel::Attributes::Attribute, Arel::Nodes::BindParam
596
- # collector = visit o.left, collector
597
- # collector << " = "
598
- # visit o.right, collector
599
- # else
600
- # collector = visit o.left, collector
601
- # collector << " = "
602
- # collector << quote(o.right, column_for(o.left)).to_s
603
- # end
604
- # end
592
+ def visit_Arel_Nodes_Assignment o, collector
593
+ case o.right
594
+ when Arel::Nodes::UnqualifiedColumn, Arel::Attributes::Attribute, Arel::Nodes::BindParam
595
+ { visit(o.left, collector) => visit(o.right, collector) }
596
+ else
597
+ collector = visit o.left, collector
598
+ collector << " = "
599
+ collector << quote(o.right, column_for(o.left)).to_s
600
+ end
601
+ end
605
602
 
606
603
  def visit_Arel_Nodes_Equality o, collector
607
604
  key = visit(o.left, collector).to_s.split('.')
@@ -637,11 +634,10 @@ module Arel
637
634
  collector
638
635
  end
639
636
 
640
- # def visit_Arel_Nodes_UnqualifiedColumn o, collector
641
- # collector << "#{quote_column_name o.name}"
642
- # collector
643
- # end
644
- #
637
+ def visit_Arel_Nodes_UnqualifiedColumn o, collector
638
+ o.name
639
+ end
640
+
645
641
  def visit_Arel_Attributes_Attribute o, collector
646
642
  join_name = o.relation.table_alias || o.relation.name
647
643
  # collector <<
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sunstone"
3
- s.version = '1.2.1'
3
+ s.version = '1.3.0'
4
4
  s.authors = ["Jon Bracy"]
5
5
  s.email = ["jonbracy@gmail.com"]
6
6
  s.homepage = "http://sunstonerb.com"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunstone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-16 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake