archon 0.0.3 → 0.0.4

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: 7e0c22aad9c7ed66bc96139044f5fd25a744d691
4
- data.tar.gz: 7e99997cb81d8b8c3f1e5c0f9a1ac989422b7712
3
+ metadata.gz: de9e479ea8d74dee6b772bcb7a3a13a279cab668
4
+ data.tar.gz: d6cf560e818c6d4bcb14ea0530043244db791db3
5
5
  SHA512:
6
- metadata.gz: 3771e614bfc9dac2b4c0e353c8e69596191c31ea92187cf1e22939006a305318619bf36573aacf676f2bf2dfceb92ca71fc8c7f501729e6b27d3350b0fc5451e
7
- data.tar.gz: f79b2f069a6af251cce7fcfce91649e5c1d553180d256813595b6d6189bf7ed70609f763d1f2e0ae0fbea8a6c6312f41201fbec4b61b787414d0a7db8aa0056e
6
+ metadata.gz: 80dedf0d2c4ae62537a3ecc94bcc621e6bcd2a07a67ed7d86a112edbcaaf1c8a4d5b711d79adc75d2bb0252bde874be4836cde408fa2f13ca8782a8e169a39d6
7
+ data.tar.gz: 3b8823e62118f6e2338ab19deec2d7690bdd9cf7447241cf25e165c3893404306077b4f923cb10387a499f38bd32867210df1f618d925ce0a14670eb0890bbb5
@@ -10,6 +10,7 @@ module Archon
10
10
  autoload :Nodes
11
11
  autoload :InsertIntoSelect
12
12
  autoload :PowerOverwhelming
13
+ autoload :Visitors
13
14
 
14
15
  def self.method_missing(called_method_name, *arguments, &block)
15
16
  # Call super to raise a method missing error if no class was loaded:
@@ -24,12 +24,16 @@ module Archon
24
24
  self.columns.concat options.fetch(
25
25
  :columns,
26
26
  ast.select.projections.map do |projection|
27
- column_name = if projection.is_a? Arel::Attributes::Attribute
27
+ column_name = case projection
28
+ when Arel::Attributes::Attribute
28
29
  projection.name
29
- elsif projection.is_a? Arel::Nodes::As
30
+ when Arel::Nodes::As
30
31
  projection.right.delete('"').to_sym
31
- elsif projection.is_a? Arel::Nodes::NamedFunction
32
+ when Arel::Nodes::NamedFunction
32
33
  projection.alias.delete('"').to_sym
34
+ when String
35
+ _table, name = projection.split('.') if projection['.']
36
+ (name || projection).delete('"').to_sym
33
37
  else
34
38
  raise "Don't know how to..."
35
39
  end
@@ -6,5 +6,6 @@ module Archon
6
6
 
7
7
  autoload :Coalesce
8
8
  autoload :PopulatedRecordset
9
+ autoload :ValuesList
9
10
  end
10
11
  end
@@ -0,0 +1,32 @@
1
+ module Archon
2
+ # Factory method
3
+ def self.values_list expressions
4
+ return Nodes::ValuesList.new expressions
5
+ end
6
+
7
+ module Nodes
8
+ class ValuesList < Arel::Nodes::Binary
9
+ alias :expressions :left
10
+ alias :expressions= :left=
11
+ alias :columns :right
12
+ alias :columns= :right=
13
+
14
+ def initialize expressions
15
+ super expressions, []
16
+ end
17
+ end
18
+ end
19
+
20
+ # Only include the visitor module on the SQL vendors that support it:
21
+ Arel::Visitors::PostgreSQL.class_eval do
22
+ include Archon::Visitors::ValuesList
23
+ end
24
+
25
+ Arel::Visitors::Oracle.class_eval do
26
+ include Archon::Visitors::ValuesList
27
+ end
28
+
29
+ Arel::Visitors::Oracle12.class_eval do
30
+ include Archon::Visitors::ValuesList
31
+ end
32
+ end
@@ -27,6 +27,14 @@ module Archon
27
27
  transaction do
28
28
  timestamp = ActiveRecord::Base.connection.quoted_date(Time.now)
29
29
  timestamp = Arel::Nodes::SqlLiteral.new("'#{timestamp}'")
30
+
31
+ insert_result = connection.execute Archon.insert_into_select(
32
+ arel_table, selectish.arel
33
+ ).to_sql
34
+
35
+ Rails.logger.debug "Inserted #{insert_result.cmd_tuples} records " \
36
+ "to table '#{arel_table.name}'."
37
+ insert_result
30
38
  end
31
39
  end
32
40
  end
@@ -1,3 +1,3 @@
1
1
  module Archon
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,8 @@
1
+ module Archon
2
+ # = Nodes
3
+ # A collection of ARel visitors to emit SQL for various SQL vendors
4
+ module Visitors
5
+ extend ActiveSupport::Autoload
6
+ autoload :ValuesList
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ module Archon
2
+ module Visitors
3
+ module ValuesList
4
+ private
5
+
6
+ def visit_Archon_Nodes_ValuesList o, collector
7
+ collector << 'VALUES '
8
+
9
+ len_a = o.expressions.length - 1
10
+ o.expressions.each_with_index do |values, i|
11
+ collector << '('
12
+ len_b = values.length - 1
13
+ values.each_with_index do |value, ii|
14
+ case value
15
+ when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
16
+ collector = visit value, collector
17
+ else
18
+ collector << quote(value).to_s
19
+ end
20
+ collector << Arel::Visitors::ToSql::COMMA unless ii == len_b
21
+ end
22
+ collector << ')'
23
+ collector << Arel::Visitors::ToSql::COMMA unless i == len_a
24
+ end
25
+
26
+ collector
27
+ end
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Quintanilla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2017-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.13'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.13'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.5'
69
69
  description: A collection of methods and classes that unleash the power of the database
@@ -74,11 +74,11 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - ".codeclimate.yml"
78
- - ".gitignore"
79
- - ".rspec"
80
- - ".rubocop.yml"
81
- - ".travis.yml"
77
+ - .codeclimate.yml
78
+ - .gitignore
79
+ - .rspec
80
+ - .rubocop.yml
81
+ - .travis.yml
82
82
  - CODE_OF_CONDUCT.md
83
83
  - Gemfile
84
84
  - LICENSE
@@ -94,8 +94,11 @@ files:
94
94
  - lib/archon/nodes.rb
95
95
  - lib/archon/nodes/coalesce.rb
96
96
  - lib/archon/nodes/populated_recordset.rb
97
+ - lib/archon/nodes/values_list.rb
97
98
  - lib/archon/power_overwhelming.rb
98
99
  - lib/archon/version.rb
100
+ - lib/archon/visitors.rb
101
+ - lib/archon/visitors/values_list.rb
99
102
  homepage: https://github.com/IcaliaLabs/archon-gem
100
103
  licenses:
101
104
  - MIT
@@ -106,17 +109,17 @@ require_paths:
106
109
  - lib
107
110
  required_ruby_version: !ruby/object:Gem::Requirement
108
111
  requirements:
109
- - - ">="
112
+ - - '>='
110
113
  - !ruby/object:Gem::Version
111
114
  version: '0'
112
115
  required_rubygems_version: !ruby/object:Gem::Requirement
113
116
  requirements:
114
- - - ">="
117
+ - - '>='
115
118
  - !ruby/object:Gem::Version
116
119
  version: '0'
117
120
  requirements: []
118
121
  rubyforge_project:
119
- rubygems_version: 2.6.8
122
+ rubygems_version: 2.0.14.1
120
123
  signing_key:
121
124
  specification_version: 4
122
125
  summary: 'ARchon: Summoning the powers of ActiveRecord and ARel to wreak havoc'