bigqueryid 0.4.0 → 0.5.2

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: ebd0bdb293a7eb11391a3da70f46f3b084301088
4
- data.tar.gz: 0c7664612aa35d696e37bc303b257b8ed260df08
3
+ metadata.gz: 70c88dd1296fdab6ac0f993a6aee623eeec9a186
4
+ data.tar.gz: 61698805be2a892b6668d8564ab8b1d843410004
5
5
  SHA512:
6
- metadata.gz: 6fc71e931b932fb59d56a9c73c48d7ca0b86b9cb73a59d5d87942d02e2578ecd7214b04f11723c709b493e8468e722720f4956163a61fd2c09886ad8f55e3e53
7
- data.tar.gz: 8573c4e24e1bdad7b1a177dfc534e7f8199821577bc60fb73cb154de5ba9c5d18464675bf07ba2a30452a04f610157cb0758de9bd50447432c3d9ca58db7162c
6
+ metadata.gz: f1f311616135eb0b4007070f3cf6b945fa8e5f594ffec55ff3ef56f93b6aae2ad8c17f42c8bb830db68e0b7041e43a50b252e71720ad05af37ddb4951a1e980a
7
+ data.tar.gz: b0bd58efb62b7622929ed0c237cbe12d92b648ae07d273496bce07a57652d5e94512984e6ba73145dc290c6024253098d353f420b57df7d9f4b301b6cd4b108e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4
5
+ - 2.3
6
+ - 2.2
7
+ before_install: gem install bundler -v 1.13.6
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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bigqueryid.gemspec
4
+ gemspec
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', :git => 'git://github.com/fabiotomio/bigqueryid.git'
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
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'bigqueryid'
5
+
6
+ require 'irb'
7
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+ set -vx
6
+
7
+ bundle install
data/lib/bigqueryid.rb CHANGED
@@ -2,6 +2,7 @@ module Bigqueryid
2
2
  require 'google/cloud/bigquery'
3
3
  require 'active_support/concern'
4
4
  require 'active_model'
5
+ require 'coercible'
5
6
 
6
7
  require 'bigqueryid/errors/bigquery_error'
7
8
  require 'bigqueryid/attributes'
@@ -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 need is Hash'
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 properties_names
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
- properties_names.each do |property|
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
@@ -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 ||= gcloud.bigquery
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
- properties_names.each { |a| send("#{a}=", options[a.to_s]) }
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) }
@@ -4,7 +4,7 @@ module Bigqueryid
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- field :created_at, default: -> { Time.now.strftime('%Y-%m-%d %H:%M:%S') }
7
+ field :created_at, type: Time, default: -> { Time.now.strftime('%Y-%m-%d %H:%M:%S %Z') }
8
8
  end
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module Bigqueryid
2
2
  # version string
3
3
  # @api public
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.2'
5
5
  end
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.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Tomio
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-24 00:00:00.000000000 Z
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.20'
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.20'
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: '4.2'
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: '4.2'
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: '4.2'
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: '4.2'
55
- description: Simple ORM to Google BigQuery
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/fabiotomio/bigqueryid
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: 2.3.0
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.7
156
+ rubygems_version: 2.6.8
92
157
  signing_key:
93
158
  specification_version: 4
94
159
  summary: Google BigQuery ORM