firestore-odm 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: 4b530cba51bdd238e2599633f45d66c50945548a60c6b37e18d33d8e2f56aac4
4
- data.tar.gz: 0b1ca53aa593fd9a028bcf83bc28f14e9eb3033484e33801512cf6f6f818df31
3
+ metadata.gz: 94b90e6ec000daec07e84a3772c145ff8e6db882205e0f384c022ac51bc8d520
4
+ data.tar.gz: b8b2a75bac4d646ef6dace0502bf9dc80a160b5f6892e5c226aa20a9e6ba130f
5
5
  SHA512:
6
- metadata.gz: 16380f656883a44abcc3b73092df5f0ec621ba8b5a70354485f6af24787e0731d46583f1a4dd562a42f496803369a3b2739cc8c5250eab0ecc4f7b2820be9bff
7
- data.tar.gz: be54202ae93445c1b6b3d5f2e020211592572096a670e2245517ab081980ec25ce0cae2c71cfe4add5d6292cfb1a551bea37711a3576090107c6965bc9ebf23c
6
+ metadata.gz: a0f9405724131206b7d0c2e379a0473bd846ec28ed4edcab94bfe7811cc7d9bf052118707779e4ee4537667b777b22a69188fde0ba28d1ca4d66262dd27b33e1
7
+ data.tar.gz: 20777dcbd8f983af757e9e487ecea5684775aa4722e805998a9cb012a45b0dc01c660e0c7bb7e7a1c297cee7d6334d4e4f4420d8959cb8d2665bf727567a4871
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
4
-
5
- group :development do
6
- gem 'solargraph'
7
- end
3
+ gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- firestore-odm (0.1.3)
4
+ firestore-odm (0.1.4)
5
5
  google-cloud-firestore (~> 1.4, >= 1.4.3)
6
6
 
7
7
  GEM
@@ -19,10 +19,10 @@ GEM
19
19
  google-cloud-core (1.5.0)
20
20
  google-cloud-env (~> 1.0)
21
21
  google-cloud-errors (~> 1.0)
22
- google-cloud-env (1.3.1)
22
+ google-cloud-env (1.3.2)
23
23
  faraday (>= 0.17.3, < 2.0)
24
- google-cloud-errors (1.0.0)
25
- google-cloud-firestore (1.4.3)
24
+ google-cloud-errors (1.0.1)
25
+ google-cloud-firestore (1.4.4)
26
26
  concurrent-ruby (~> 1.0)
27
27
  google-cloud-core (~> 1.2)
28
28
  google-gax (~> 1.8)
@@ -35,21 +35,21 @@ GEM
35
35
  googleauth (~> 0.9)
36
36
  grpc (~> 1.24)
37
37
  rly (~> 0.2.3)
38
- google-protobuf (3.12.1-universal-darwin)
38
+ google-protobuf (3.12.2)
39
39
  googleapis-common-protos (1.3.10)
40
40
  google-protobuf (~> 3.11)
41
41
  googleapis-common-protos-types (>= 1.0.5, < 2.0)
42
42
  grpc (~> 1.27)
43
43
  googleapis-common-protos-types (1.0.5)
44
44
  google-protobuf (~> 3.11)
45
- googleauth (0.12.0)
45
+ googleauth (0.13.0)
46
46
  faraday (>= 0.17.3, < 2.0)
47
47
  jwt (>= 1.4, < 3.0)
48
48
  memoist (~> 0.16)
49
49
  multi_json (~> 1.11)
50
50
  os (>= 0.9, < 2.0)
51
51
  signet (~> 0.14)
52
- grpc (1.28.0-universal-darwin)
52
+ grpc (1.28.0)
53
53
  google-protobuf (~> 3.11)
54
54
  googleapis-common-protos-types (~> 1.0)
55
55
  jaro_winkler (1.5.4)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'firestore-odm'
3
- spec.version = '0.1.4'
3
+ spec.version = '0.1.5'
4
4
  spec.licenses = 'BSD-2-Clause'
5
5
  spec.summary = 'ODM for Firestore in Ruby'
6
6
  spec.description = ''
@@ -10,5 +10,5 @@ Gem::Specification.new do |spec|
10
10
  spec.homepage = 'https://github.com/fecabrera/firestore-odm'
11
11
  spec.metadata = {"source_code_uri" => "https://github.com/fecabrera/firestore-odm"}
12
12
 
13
- spec.add_dependency 'google-cloud-firestore', '~> 1.4', '>= 1.4.3'
13
+ spec.add_dependency 'google-cloud-firestore', '~> 1.4', '>= 1.4.0'
14
14
  end
@@ -17,7 +17,7 @@ class Module
17
17
  end
18
18
 
19
19
  module FirestoreODM
20
- attr_reader :conversions
20
+ attr_reader :conversions, :options
21
21
 
22
22
  @conversions = {
23
23
  String => :to_s,
@@ -28,6 +28,8 @@ module FirestoreODM
28
28
  Time => :to_time
29
29
  }
30
30
 
31
+ @options = {}
32
+
31
33
  # Sets a conversion rule for a certain type.
32
34
  # @param type [Class]
33
35
  # @param target [Symbol, Proc]
@@ -50,32 +52,42 @@ module FirestoreODM
50
52
  end
51
53
  end
52
54
 
53
- def more_than value
54
- Proc.new { |o| value < o }
55
+ # @param name [Symbol]
56
+ def add_option name, &block
57
+ @options[name] = block
55
58
  end
56
59
 
57
- def min value
58
- Proc.new { |o| value <= o }
59
- end
60
-
61
- def max value
62
- Proc.new { |o| o <= value }
63
- end
64
-
65
- def less_than value
66
- Proc.new { |o| o < value }
67
- end
68
-
69
- def check_option name, option
70
- method = FirestoreODM.method name
60
+ def get_option name, option
61
+ method = @options[name]
71
62
 
72
63
  case option
73
64
  when Proc
74
- check_option name, option.call
65
+ get_option name, option.call
75
66
  else
76
67
  method.call option
77
68
  end
78
69
  end
79
70
 
80
71
  extend self
72
+ end
73
+
74
+
75
+ FirestoreODM.add_option :more_than do |value|
76
+ Proc.new { |o| value < o }
77
+ end
78
+
79
+ FirestoreODM.add_option :min do |value|
80
+ Proc.new { |o| value <= o }
81
+ end
82
+
83
+ FirestoreODM.add_option :max do |value|
84
+ Proc.new { |o| o <= value }
85
+ end
86
+
87
+ FirestoreODM.add_option :less_than do |value|
88
+ Proc.new { |o| o < value }
89
+ end
90
+
91
+ FirestoreODM.add_option :in do |list|
92
+ Proc.new { |o| list.include? o }
81
93
  end
@@ -9,10 +9,11 @@ module FirestoreODM
9
9
 
10
10
  list = []
11
11
 
12
- list << FirestoreODM.check_option(:min, opts[:min]) if opts[:min]
13
- list << FirestoreODM.check_option(:max, opts[:max]) if opts[:max]
14
- list << FirestoreODM.check_option(:less_than, opts[:less_than]) if opts[:less_than]
15
- list << FirestoreODM.check_option(:more_than, opts[:more_than]) if opts[:more_than]
12
+ list << FirestoreODM.get_option(:min, opts[:min]) if opts[:min]
13
+ list << FirestoreODM.get_option(:max, opts[:max]) if opts[:max]
14
+ list << FirestoreODM.get_option(:less_than, opts[:less_than]) if opts[:less_than]
15
+ list << FirestoreODM.get_option(:more_than, opts[:more_than]) if opts[:more_than]
16
+ list << FirestoreODM.get_option(:in, opts[:in]) if opts[:in]
16
17
 
17
18
  define_singleton_method("parse_#{name}") do |value|
18
19
  list.reduce(true) { |result, o| result and o.call(value) }
data/test.rb CHANGED
@@ -7,6 +7,7 @@ class Post < FirestoreODM::Model
7
7
  path :posts
8
8
 
9
9
  field :content, String
10
+ field :privacy, String, :in => ['public', 'hidden', 'private']
10
11
  field :created_at, DateTime
11
12
  end
12
13
 
@@ -31,6 +32,8 @@ end
31
32
  puts Account.parse_birthday(Date.parse('2001-12-02'))
32
33
  puts Account.parse_birthday(Date.parse('2002-12-02'))
33
34
  puts Account.parse_birthday(Date.parse('2003-12-02'))
35
+ puts Post.parse_privacy('public')
36
+ puts Post.parse_privacy('none')
34
37
 
35
38
  begin
36
39
  user = User.create_with_id 'john.smith' do |doc|
@@ -58,6 +61,7 @@ begin
58
61
 
59
62
  post = user.create_post do |doc|
60
63
  doc.content = 'Hello world!'
64
+ doc.privacy = 'public'
61
65
  doc.created_at = DateTime.now
62
66
  end
63
67
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firestore-odm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Cabrera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-15 00:00:00.000000000 Z
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-firestore
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.4'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.4.3
22
+ version: 1.4.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.4'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.4.3
32
+ version: 1.4.0
33
33
  description: ''
34
34
  email: fecabrera0@outlook.com
35
35
  executables: []
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.0.8
71
+ rubygems_version: 3.1.2
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: ODM for Firestore in Ruby