db2_query 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/db2_query/railtie.rb +5 -0
- data/lib/db2_query/tasks.rb +2 -2
- data/lib/db2_query/version.rb +1 -1
- data/lib/db2_query.rb +1 -0
- data/lib/generators/query/USAGE +15 -0
- data/lib/generators/query/query_generator.rb +70 -0
- data/lib/generators/query/templates/query.rb.tt +26 -0
- data/lib/generators/query/templates/query_definitions.rb.tt +18 -0
- data/lib/generators/query/templates/unit_test.rb.tt +9 -0
- data/lib/tasks/database.rake +10 -0
- data/lib/tasks/init.rake +9 -0
- data/lib/tasks/initializer.rake +10 -0
- data/lib/tasks/templates/database.rb.tt +19 -0
- data/lib/tasks/templates/initializer.rb.tt +8 -0
- metadata +12 -3
- data/lib/tasks/db2_query_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9eabc77ee406196782e5a07a95a7e821d169ec98b865443c7c7450f337d09d5e
|
4
|
+
data.tar.gz: 84089fa859c9777a38d3b8698b4789993b5769fcc13d6ba093202d68cd9f6456
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e83b1e40ff7e6e949657aadbdedebdbd106f8ddb6f5143fee15b94b655b4c7306a80025d5884c81b3d0a1092ac058241c2c9cd0092318dec131a863567b7b5d8
|
7
|
+
data.tar.gz: 6d1c87212f770d85f5657744b7ddbca5d6b09e3ff903b227651f6b33915a586bbf5ce7ac00924923bae13a024434b219dae606a65deaebe4ff857e5d84f8153d
|
data/lib/db2_query/railtie.rb
CHANGED
data/lib/db2_query/tasks.rb
CHANGED
@@ -12,7 +12,7 @@ module Db2Query
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class DatabaseTask < Tasks
|
15
|
-
source_root File.expand_path("
|
15
|
+
source_root File.expand_path("../../tasks/templates", __FILE__)
|
16
16
|
|
17
17
|
def create_database_config_file
|
18
18
|
template "database.rb", File.join("config/db2query.yml")
|
@@ -20,7 +20,7 @@ module Db2Query
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class InitializerTask < Tasks
|
23
|
-
source_root File.expand_path("
|
23
|
+
source_root File.expand_path("../../tasks/templates", __FILE__)
|
24
24
|
|
25
25
|
def create_initializer_file
|
26
26
|
template "initializer.rb", File.join("config/initializers/db2query.rb")
|
data/lib/db2_query/version.rb
CHANGED
data/lib/db2_query.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a new query. Pass the query name, either
|
3
|
+
CamelCased or under_scored, and an optional list of its methods as arguments.
|
4
|
+
|
5
|
+
To create a query within a module, just use namespace pattern as the other rails generators do.
|
6
|
+
|
7
|
+
To create query class methods, you can use 3 options:
|
8
|
+
1. Plain SQL methods --defines
|
9
|
+
2. Query Methods with SQL string, --queries
|
10
|
+
3. Query Methods with lambda, --lambdas
|
11
|
+
|
12
|
+
Example:
|
13
|
+
$ rails g query NameSpace::Name --queries query_1 --defines query_2 --lambdas query_3
|
14
|
+
create app/queries/name_space/name_query.rb
|
15
|
+
create test/queries/name_space/name_query_test.rb
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
module Generators
|
8
|
+
class QueryGenerator < Rails::Generators::NamedBase
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
class_option :skip_unit_test, type: :boolean, default: false, desc: "Skip unit test file creation"
|
12
|
+
class_option :defines, type: :array, default: [], desc: "Plain query method options"
|
13
|
+
class_option :queries, type: :array, default: [], desc: "Query method SQL options"
|
14
|
+
class_option :lambdas, type: :array, default: [], desc: "Query method with callable args"
|
15
|
+
|
16
|
+
def create_query_file
|
17
|
+
template "query.rb", File.join("app/queries", class_path, "#{file_name}_query.rb")
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_query_definitions_file
|
21
|
+
template "query_definitions.rb", File.join("app/queries/definitions", class_path, "#{file_name}_query_definitions.rb")
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_query_test_file
|
25
|
+
unless options[:skip_unit_test]
|
26
|
+
template "unit_test.rb", File.join("test/queries", class_path, "#{file_name}_query_test.rb")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def assign_names!(name)
|
32
|
+
super(name)
|
33
|
+
@method_options = options.slice("defines", "queries", "lambdas")
|
34
|
+
@query_methods = @method_options.map { |key, val| val }.flatten
|
35
|
+
end
|
36
|
+
|
37
|
+
def query_class_name
|
38
|
+
"#{file_name.camelize}Query"
|
39
|
+
end
|
40
|
+
|
41
|
+
def namespaced_query?
|
42
|
+
!class_path.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
def namespaced_names
|
46
|
+
class_path
|
47
|
+
end
|
48
|
+
|
49
|
+
def namespaced_content(content)
|
50
|
+
namespaced_names.reverse_each do |namespace_name|
|
51
|
+
content = "module #{namespace_name.camelize}\n#{indent(content)}\nend"
|
52
|
+
end
|
53
|
+
content
|
54
|
+
end
|
55
|
+
|
56
|
+
def module_namespacing(&block)
|
57
|
+
content = capture(&block)
|
58
|
+
content = namespaced_content(content) if namespaced_query?
|
59
|
+
concat(content)
|
60
|
+
end
|
61
|
+
|
62
|
+
def module_definitions_namespacing(&block)
|
63
|
+
content = capture(&block)
|
64
|
+
content = namespaced_content(content) if namespaced_query?
|
65
|
+
definitions_namespace_content = "module Definitions\n#{indent(content)}\nend"
|
66
|
+
concat(definitions_namespace_content)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= query_class_name %> < <%= "Db2Query::Base" -%>
|
5
|
+
<% if @query_methods.empty? %>
|
6
|
+
<%= indent("query :to_do, <<-SQL\n") %>
|
7
|
+
<%= indent("SQL\n") %>
|
8
|
+
<%= indent("def to_do_sql\n") %>
|
9
|
+
<%= indent("end") %>
|
10
|
+
<% end -%>
|
11
|
+
<% @method_options.each do |key, val| -%>
|
12
|
+
<% val.each_with_index do |option, index| -%>
|
13
|
+
<% case key when 'defines' -%>
|
14
|
+
<%= indent("def #{option}_sql\n") %>
|
15
|
+
<%= indent("end") %>
|
16
|
+
<% when 'queries' %>
|
17
|
+
<%= indent("query :#{option}, <<-SQL\n") %>
|
18
|
+
<%= indent("SQL") %>
|
19
|
+
<% when 'lambdas' %>
|
20
|
+
<%= indent("query :#{option}, -> args {\n") %>
|
21
|
+
<%= indent("}") %>
|
22
|
+
<% end -%>
|
23
|
+
<% end -%>
|
24
|
+
<% end -%>
|
25
|
+
<%= 'end' -%>
|
26
|
+
<% end %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% module_definitions_namespacing do -%>
|
4
|
+
class <%= query_class_name %>Definitions < <%= "Db2Query::Definitions" %>
|
5
|
+
<% if @query_methods.empty? %>
|
6
|
+
<%= indent("def describe\n") -%>
|
7
|
+
<%= indent("") %>
|
8
|
+
<%= indent("end") %>
|
9
|
+
<% else %>
|
10
|
+
<%= indent("def describe") -%>
|
11
|
+
<% @query_methods.each do |method| %>
|
12
|
+
<%= indent("query_definition :#{method} do |c|\n") %>
|
13
|
+
<%= indent("end") %>
|
14
|
+
<% end -%>
|
15
|
+
<%= indent("end") %>
|
16
|
+
<% end %>
|
17
|
+
<%= 'end' -%>
|
18
|
+
<% end %>
|
data/lib/tasks/init.rake
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db2_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yohanes Lumentut
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -125,7 +125,16 @@ files:
|
|
125
125
|
- lib/db2_query/type/timestamp.rb
|
126
126
|
- lib/db2_query/type/value.rb
|
127
127
|
- lib/db2_query/version.rb
|
128
|
-
- lib/
|
128
|
+
- lib/generators/query/USAGE
|
129
|
+
- lib/generators/query/query_generator.rb
|
130
|
+
- lib/generators/query/templates/query.rb.tt
|
131
|
+
- lib/generators/query/templates/query_definitions.rb.tt
|
132
|
+
- lib/generators/query/templates/unit_test.rb.tt
|
133
|
+
- lib/tasks/database.rake
|
134
|
+
- lib/tasks/init.rake
|
135
|
+
- lib/tasks/initializer.rake
|
136
|
+
- lib/tasks/templates/database.rb.tt
|
137
|
+
- lib/tasks/templates/initializer.rb.tt
|
129
138
|
homepage: https://github.com/yohaneslumentut/db2_query
|
130
139
|
licenses:
|
131
140
|
- MIT
|