bigqueryid 0.4.0 → 0.5.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 +4 -4
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +6 -2
- data/Rakefile +10 -0
- data/bigqueryid.gemspec +31 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/lib/bigqueryid.rb +1 -0
- data/lib/bigqueryid/attributes.rb +63 -4
- data/lib/bigqueryid/base.rb +1 -5
- data/lib/bigqueryid/base/initializable.rb +1 -1
- data/lib/bigqueryid/timestamps.rb +1 -1
- data/lib/bigqueryid/version.rb +1 -1
- metadata +78 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70c88dd1296fdab6ac0f993a6aee623eeec9a186
|
4
|
+
data.tar.gz: 61698805be2a892b6668d8564ab8b1d843410004
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f311616135eb0b4007070f3cf6b945fa8e5f594ffec55ff3ef56f93b6aae2ad8c17f42c8bb830db68e0b7041e43a50b252e71720ad05af37ddb4951a1e980a
|
7
|
+
data.tar.gz: b0bd58efb62b7622929ed0c237cbe12d92b648ae07d273496bce07a57652d5e94512984e6ba73145dc290c6024253098d353f420b57df7d9f4b301b6cd4b108e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
## 0.5.0 (2016-11-25)
|
2
|
+
|
3
|
+
### Update dependencies
|
4
|
+
|
5
|
+
- Update rails gems to ~> 5.0
|
6
|
+
- Update google cloud to ~> 0.21
|
7
|
+
|
8
|
+
### Improve project structure
|
9
|
+
|
10
|
+
- Add bin/console to open interactive console
|
11
|
+
- Add bin/setup to setup project in development mode
|
12
|
+
- Add additional files (like a bundle gem ... generated files)
|
13
|
+
|
14
|
+
|
15
|
+
## 0.4.0 (2016-11-24)
|
16
|
+
|
17
|
+
- Delegated enviroment variables handling to "google-cloud-bigquery"
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Fabio Tomio
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ gem install bigqueryid-<version>.gem
|
|
10
10
|
```
|
11
11
|
or
|
12
12
|
```ruby
|
13
|
-
gem 'bigqueryid'
|
13
|
+
gem 'bigqueryid'
|
14
14
|
```
|
15
15
|
|
16
16
|
Configure
|
@@ -31,6 +31,10 @@ class Product
|
|
31
31
|
dataset 'core'
|
32
32
|
table 'products'
|
33
33
|
|
34
|
+
field :name, type: String
|
35
|
+
field :price, type: Float
|
36
|
+
field :barcode
|
37
|
+
|
34
38
|
def self.create_table
|
35
39
|
bigquery.dataset(self.dataset_name).create_table self.table_name do |schema|
|
36
40
|
schema.string 'barcode'
|
@@ -66,4 +70,4 @@ Product.flush
|
|
66
70
|
# Fetch all rows
|
67
71
|
Product.fetch_all
|
68
72
|
|
69
|
-
```
|
73
|
+
```
|
data/Rakefile
ADDED
data/bigqueryid.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bigqueryid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'bigqueryid'
|
8
|
+
spec.version = Bigqueryid::VERSION
|
9
|
+
spec.summary = 'Google BigQuery ORM'
|
10
|
+
spec.description = 'Simple ORM for Google BigQuery'
|
11
|
+
spec.authors = ['Fabio Tomio']
|
12
|
+
spec.email = 'fabiotomio@gmail.com'
|
13
|
+
spec.homepage = 'http://github.com/b2beauty/bigqueryid'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
26
|
+
|
27
|
+
spec.add_dependency 'google-cloud-bigquery', '~> 0.21'
|
28
|
+
spec.add_dependency 'activesupport', '~> 5.0'
|
29
|
+
spec.add_dependency 'activemodel', '~> 5.0'
|
30
|
+
spec.add_dependency 'coercible', '~> 1.0'
|
31
|
+
end
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/bigqueryid.rb
CHANGED
@@ -14,13 +14,13 @@ module Bigqueryid
|
|
14
14
|
if attributes.is_a? ::Hash
|
15
15
|
attributes.each_pair { |key, value| send("#{key}=", value) }
|
16
16
|
else
|
17
|
-
raise Bigqueryid::Errors::BigqueryError.new 'Attributes params
|
17
|
+
raise Bigqueryid::Errors::BigqueryError.new 'Attributes params must be a Hash'
|
18
18
|
end
|
19
19
|
rescue
|
20
20
|
raise Bigqueryid::Errors::BigqueryError.new 'Attribute invalid'
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def attributes_names
|
24
24
|
attributes.keys
|
25
25
|
end
|
26
26
|
|
@@ -37,11 +37,69 @@ module Bigqueryid
|
|
37
37
|
|
38
38
|
def to_hash
|
39
39
|
hash = {}
|
40
|
-
|
40
|
+
attributes_names.each do |property|
|
41
41
|
hash[property] = send(property)
|
42
42
|
end
|
43
43
|
hash.sort.to_h
|
44
44
|
end
|
45
|
+
|
46
|
+
def coercer
|
47
|
+
@coercer ||= Coercible::Coercer.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def coerce(value, type)
|
51
|
+
if value.nil? || !type
|
52
|
+
value
|
53
|
+
else
|
54
|
+
case
|
55
|
+
when Array == type || Array === type then coerce_array(value, type)
|
56
|
+
when Hash == type || Hash === type then coerce_hash(value, type)
|
57
|
+
when type == Time then coerce_time(value)
|
58
|
+
else coerce_other(value, type)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def coerce_array(value, type)
|
65
|
+
# type: generic Array
|
66
|
+
if type == Array
|
67
|
+
coerce_other(value, type)
|
68
|
+
# type: Array[Something]
|
69
|
+
elsif value.respond_to?(:map)
|
70
|
+
value.map do |element|
|
71
|
+
coerce(element, type[0])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
raise ArgumentError.new "Invalid coercion: #{value.class} => #{type}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def coerce_hash(value, type)
|
79
|
+
# type: generic Hash
|
80
|
+
if type == Hash
|
81
|
+
coerce_other(value, type)
|
82
|
+
# type: Hash[Something => Other thing]
|
83
|
+
elsif value.respond_to?(:to_h)
|
84
|
+
k_type, v_type = type.to_a[0]
|
85
|
+
value.to_h.map{ |k,v| [ coerce(k, k_type), coerce(v, v_type) ] }.to_h
|
86
|
+
else
|
87
|
+
raise ArgumentError.new "Invalid coercion: #{value.class} => #{type}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def coerce_time(value)
|
92
|
+
case value
|
93
|
+
when Integer, Float then Time.at(value)
|
94
|
+
when /\d{4}-\d{2}-\d{2}/ then Time.parse(value)
|
95
|
+
when /\A\d+(\.\d+)?/ then Time.at(value.to_f)
|
96
|
+
else value
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def coerce_other(value, type)
|
101
|
+
coercer[value.class].send("to_#{type.to_s.downcase}", value)
|
102
|
+
end
|
45
103
|
end
|
46
104
|
|
47
105
|
class_methods do
|
@@ -61,8 +119,9 @@ module Bigqueryid
|
|
61
119
|
define_method(name) do # Define get method
|
62
120
|
instance_variable_get("@#{name}")
|
63
121
|
end
|
122
|
+
|
64
123
|
define_method("#{name}=") do |value| # Define set method
|
65
|
-
instance_variable_set("@#{name}", value)
|
124
|
+
instance_variable_set("@#{name}", coerce(value, attributes[name][:type]))
|
66
125
|
end
|
67
126
|
end
|
68
127
|
end
|
data/lib/bigqueryid/base.rb
CHANGED
@@ -22,12 +22,8 @@ module Bigqueryid
|
|
22
22
|
self.table_name = name
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.gcloud
|
26
|
-
Google::Cloud.new
|
27
|
-
end
|
28
|
-
|
29
25
|
def self.bigquery
|
30
|
-
@bigquery_connection ||=
|
26
|
+
@bigquery_connection ||= Google::Cloud::Bigquery.new
|
31
27
|
end
|
32
28
|
|
33
29
|
def self.gcloud_table
|
@@ -8,7 +8,7 @@ module Bigqueryid
|
|
8
8
|
def initialize(options = nil)
|
9
9
|
set_default_values
|
10
10
|
if options.is_a? Google::Cloud::Bigquery::Data
|
11
|
-
|
11
|
+
attributes_names.each { |a| send("#{a}=", options[a.to_s]) }
|
12
12
|
send('id=', options.key.id)
|
13
13
|
elsif options.is_a? ::Hash
|
14
14
|
options.each_pair { |key, value| send("#{key}=", value) }
|
data/lib/bigqueryid/version.rb
CHANGED
metadata
CHANGED
@@ -1,64 +1,129 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigqueryid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Tomio
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: google-cloud-bigquery
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
16
58
|
requirements:
|
17
59
|
- - "~>"
|
18
60
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
61
|
+
version: '0.21'
|
20
62
|
type: :runtime
|
21
63
|
prerelease: false
|
22
64
|
version_requirements: !ruby/object:Gem::Requirement
|
23
65
|
requirements:
|
24
66
|
- - "~>"
|
25
67
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
68
|
+
version: '0.21'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: activesupport
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
30
72
|
requirements:
|
31
73
|
- - "~>"
|
32
74
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
75
|
+
version: '5.0'
|
34
76
|
type: :runtime
|
35
77
|
prerelease: false
|
36
78
|
version_requirements: !ruby/object:Gem::Requirement
|
37
79
|
requirements:
|
38
80
|
- - "~>"
|
39
81
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
82
|
+
version: '5.0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: activemodel
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
87
|
- - "~>"
|
46
88
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
89
|
+
version: '5.0'
|
48
90
|
type: :runtime
|
49
91
|
prerelease: false
|
50
92
|
version_requirements: !ruby/object:Gem::Requirement
|
51
93
|
requirements:
|
52
94
|
- - "~>"
|
53
95
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coercible
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
description: Simple ORM for Google BigQuery
|
56
112
|
email: fabiotomio@gmail.com
|
57
113
|
executables: []
|
58
114
|
extensions: []
|
59
115
|
extra_rdoc_files: []
|
60
116
|
files:
|
117
|
+
- ".gitignore"
|
118
|
+
- ".travis.yml"
|
119
|
+
- CHANGELOG.md
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
61
122
|
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bigqueryid.gemspec
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
62
127
|
- lib/bigqueryid.rb
|
63
128
|
- lib/bigqueryid/attributes.rb
|
64
129
|
- lib/bigqueryid/base.rb
|
@@ -68,7 +133,7 @@ files:
|
|
68
133
|
- lib/bigqueryid/errors/bigquery_error.rb
|
69
134
|
- lib/bigqueryid/timestamps.rb
|
70
135
|
- lib/bigqueryid/version.rb
|
71
|
-
homepage: http://github.com/
|
136
|
+
homepage: http://github.com/b2beauty/bigqueryid
|
72
137
|
licenses:
|
73
138
|
- MIT
|
74
139
|
metadata: {}
|
@@ -80,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
145
|
requirements:
|
81
146
|
- - ">="
|
82
147
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
148
|
+
version: '0'
|
84
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
150
|
requirements:
|
86
151
|
- - ">="
|
@@ -88,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
153
|
version: '0'
|
89
154
|
requirements: []
|
90
155
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.6.
|
156
|
+
rubygems_version: 2.6.8
|
92
157
|
signing_key:
|
93
158
|
specification_version: 4
|
94
159
|
summary: Google BigQuery ORM
|