relationize 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07f7ffbde936c2f83c3b79ce5f68cf2e0edb52d2
4
- data.tar.gz: 1d3229ecbd96fd5f434d0516ee250aca286cae04
3
+ metadata.gz: 318275fead880f40d29c8bc17bf75ef54ddcfa4b
4
+ data.tar.gz: 33951015d7daae1bc5900391ea6da52158560753
5
5
  SHA512:
6
- metadata.gz: 46fd2f2519ddd1ae60c099b20c9929ada3fa6aec5533a0c53fabea611bba254e2595b8b7b7893c975e92d63bf7e4e8b6c0428bc3a36dac37c6a87055bcf29fcc
7
- data.tar.gz: 9748eb06f27f2a6b24b3313f9b188ea16d2b4ab9a6a39d4a60d978a2243f0169549f6898c5a2c4ba25df685d4f6038fb5869ac19c751ca9fdeffbc9e5ea3f79a
6
+ metadata.gz: 3f6662e1d06b406af4795652bf66a00feebef2f5236cf2680058568f2cceca750381ec20071e4163dd160caa9c84236957b55210ed593ba61a3371ea10416301
7
+ data.tar.gz: 57efe17d897e121e8ea0f802a68bcd73c76445482aab52bac7fbdb5b7d9eca5c548be8b4962aa851ff8499878dea56f8c11429e16b47d53bd38c070fd7daa1dc
data/README.md CHANGED
@@ -35,40 +35,28 @@ puts [["'a'"]].to_relation(schema: { a: nil })
35
35
  #=> SELECT "a"::TEXT FROM (VALUES('''a''')) AS "_t"("a")
36
36
  ```
37
37
 
38
- ### PostgreSQL
38
+ ### Usage for PostgreSQL
39
39
 
40
40
  ```ruby
41
41
  require 'relationize'
42
-
43
- class Hoge
44
- using Relationize
45
-
46
- def initialize(data, schema)
47
- @data = data
48
- @schema = schema
49
- end
50
-
51
- def to_sql
52
- @data.to_relation(schema: @schema)
53
- end
54
- end
55
-
56
42
  require 'pg'
57
43
 
58
- hoge = Hoge.new(
59
- [[1, 2, 3], [4, 5, 6]],
60
- {a: nil, b: nil, c: :decimal}
61
- )
44
+ using Relationize
45
+
46
+ sql = [
47
+ [1, 2, 3],
48
+ [4, 5, 6]
49
+ ].to_relation(schema: {a: nil, b: nil, c: :decimal})
62
50
 
63
- p PG.connect.exec(hoge.to_sql).to_a
51
+ p PG.connect.exec(sql).to_a
64
52
  #=> [{"a"=>"1", "b"=>"2", "c"=>"3"}, {"a"=>"4", "b"=>"5", "c"=>"6"}]
65
53
 
66
54
  p PG.connect.exec(<<-SQL).to_a #=> [{"a"=>"1", "b"=>"2", "c"=>"3"}]
67
- SELECT * FROM (#{hoge.to_sql}) AS t WHERE "a" < 3
55
+ SELECT * FROM (#{sql}) AS t WHERE "a" < 3
68
56
  SQL
69
57
 
70
58
  p PG.connect.exec(<<-SQL).to_a #=> [{"a"=>"4", "b"=>"5", "c"=>"6"}]
71
- WITH t AS (#{hoge.to_sql})
59
+ WITH t AS (#{sql})
72
60
  SELECT * FROM t WHERE t."a" > 3
73
61
  SQL
74
62
  ```
@@ -1,3 +1,5 @@
1
+ require 'hash/to_proc'
2
+
1
3
  module Relationize
2
4
  #
3
5
  # Relationizer Base Class
@@ -35,7 +37,7 @@ module Relationize
35
37
  next type.to_s.upcase if type
36
38
 
37
39
  values.map(&:class).uniq.
38
- map { |klass| self.class::DEFAULT_TYPES[klass] }.compact.uniq.
40
+ map(&self.class::DEFAULT_TYPES).compact.uniq.
39
41
  tap { |types| raise ReasonlessTypeError.new("Many candidate: #{types.join(', ')}") unless types.one? }.
40
42
  tap { |types| raise ReasonlessTypeError.new("Candidate nothing") if types.empty? }.
41
43
  first.to_s.upcase
@@ -1,3 +1,3 @@
1
1
  module Relationize
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/relationize.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_dependency "hash-to_proc"
22
23
  spec.add_development_dependency "bundler", "~> 1.11"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "minitest", "~> 5.0"
25
25
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relationize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yancya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: hash-to_proc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
20
- type: :development
19
+ version: '0'
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
- version: '1.11'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '1.11'
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
- version: '10.0'
40
+ version: '1.11'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
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
- version: '5.0'
54
+ version: '10.0'
55
55
  description: This gem generate evaluable string as relation in RDB
56
56
  email:
57
57
  - yancya@upec.jp