pubsub_tie 1.0.0 → 1.3.0

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
  SHA256:
3
- metadata.gz: 34f6b84fac7ce4deacc85da202eb97c5991a8d39f8cb655eae8f1aff487316d9
4
- data.tar.gz: 874c65f960fd033f90b70262f7dc06e282470a31190351b8fafeea01e924ec37
3
+ metadata.gz: 5197e991980aaa66203f85ae0578f2c99084be20ed97ab09095a76a7f172d0bf
4
+ data.tar.gz: 99a5cf74320f78e410a3cec82fbd71304748b8428f4fb8a56a0ef41e1a2b22e6
5
5
  SHA512:
6
- metadata.gz: 8653c31411d06e09597d7bab07e5ed27f196cc82f623f0848fcacc8397def04768df71122cb6d5254b946abf5bb140dde88677fe1ed4d176658606c268a9c1c1
7
- data.tar.gz: e97c1edc4606b1e9f8662f54178b13853a74b323a29327fb5d51302bb7475220975a6fc5b9cbf04f103d0385ad0efcaf750b5d0843bb1ae3cd07eb9fc96590cb
6
+ metadata.gz: bd220c7966605d989e9c5f9c71c23cf8680d575726031348037e9fbc33718aa16ac89f807ad46f9cb1027a26e911ecc7dcc157efe5ee6ff70e76dfdf48eac49b
7
+ data.tar.gz: 8751592fe85ad07e015591f22f83964e43889d8454bc631efc1f52abdeeb3a2bd42dc2b6047fced3f62cb574c74f647ba5933b7bc563d10232cce35778b43108
@@ -8,7 +8,9 @@ module PubSubTie
8
8
  evs = config['events'].map{|e| e['name']}
9
9
  @events = Hash[evs.map(&:to_sym).zip(config['events'])]
10
10
  @events.each do |k, evt|
11
- fields = (evt['required'] || []) + (evt['optional'] || [])
11
+ fields = (evt['required'] || []) +
12
+ (evt['optional'] || []) +
13
+ (evt['repeated'] || [])
12
14
  evt['fields'] = Hash[ fields.map {|f| [f['name'], f['type']]} ]
13
15
  end
14
16
  end
@@ -28,7 +30,11 @@ module PubSubTie
28
30
  end
29
31
 
30
32
  def optional(sym)
31
- field_names(sym, 'optional')
33
+ field_names(sym, 'optional') + repeated(sym)
34
+ end
35
+
36
+ def repeated(sym)
37
+ field_names(sym, 'repeated')
32
38
  end
33
39
 
34
40
  def types(sym)
@@ -79,28 +79,35 @@ module PubSubTie
79
79
  end
80
80
 
81
81
  def validate_types(sym, data)
82
- types = Events.types(sym)
83
-
84
82
  data.each do |field, val|
85
- case val
86
- when String
87
- bad_type(field, data) unless types[field.to_s] == "STRING"
88
- when Integer
89
- bad_type(field, data) unless ["INT", "FLOAT"].include? types[field.to_s]
90
- when Numeric
91
- bad_type(field, data) unless types[field.to_s] == "FLOAT"
92
- when Time
93
- bad_type(field, data) unless types[field.to_s] == "TIMESTAMP"
94
- when DateTime
95
- bad_type(field, data) unless types[field.to_s] == "DATETIME"
96
- else
97
- bad_type(field, data)
98
- end
83
+ validate_type(field, val, data, sym)
99
84
  end
100
85
 
101
86
  data
102
87
  end
103
88
 
89
+ def validate_type(field, val, data, sym)
90
+ types = Events.types(sym)
91
+
92
+ case val
93
+ when String
94
+ bad_type(field, data) unless types[field.to_s] == "STRING"
95
+ when Integer
96
+ bad_type(field, data) unless ["INT", "FLOAT", "INT64", "SMALLINT", "INTEGER", "BIGINT", "TINYINT", "BYTEINT"].include? types[field.to_s]
97
+ when Numeric
98
+ bad_type(field, data) unless ["DECIMAL", "BIGDECIMAL", "FLOAT", "FLOAT64"].include? types[field.to_s]
99
+ when Time
100
+ bad_type(field, data) unless types[field.to_s] == "TIMESTAMP"
101
+ when DateTime
102
+ bad_type(field, data) unless types[field.to_s] == "DATETIME"
103
+ when Array
104
+ bad_type(field, data) unless Events.repeated(sym).include? field
105
+ val.each {|elem| validate_type(field, elem, data, sym) }
106
+ else
107
+ bad_type(field, data)
108
+ end
109
+ end
110
+
104
111
  def bad_type(field, data)
105
112
  raise ArgumentError.new("Bad type for field #{field} in event #{data}")
106
113
  end
@@ -1,3 +1,3 @@
1
1
  module PubSubTie
2
- VERSION = "1.0.0"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/pubsub_tie.rb CHANGED
@@ -23,7 +23,7 @@ module PubSubTie
23
23
  end
24
24
 
25
25
  def env
26
- @env ||= defined?(Rails) ? Rails.env : ENV["ENV"] || 'developent'
26
+ @env ||= defined?(Rails) ? Rails.env : ENV["ENV"] || 'development'
27
27
  end
28
28
 
29
29
  def configure_publisher
@@ -32,7 +32,7 @@ module PubSubTie
32
32
  end
33
33
 
34
34
  def configure_events
35
- config = YAML.load_file(File.join(app_root, 'config', 'events.yml'))
35
+ config = YAML.load_file(File.join(app_root, 'config', 'events.yml'))[env]
36
36
  Events.configure(config)
37
37
  end
38
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubsub_tie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Calderon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-15 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-pubsub
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.16'
61
+ version: 2.1.4
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.16'
68
+ version: 2.1.4
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubygems_version: 3.0.3
114
+ rubygems_version: 3.1.4
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Hook for Google PubSub for publication of events enforcing autoimposed rules