protip 0.32.2 → 0.35.3

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
- SHA1:
3
- metadata.gz: 0e1fbe6b7ee1d780392ae6ff7db663082ea2eb2b
4
- data.tar.gz: 28855eb50758306090c18f4d571e4a26959fcbcb
2
+ SHA256:
3
+ metadata.gz: a8dc5147627d4163ebde05751c7bdfd92b1e788f9490830490346c1c83f95e7f
4
+ data.tar.gz: 7c837443f9502742f7204d6f7e58185c8f1c64f4480753562ba2364fa014d932
5
5
  SHA512:
6
- metadata.gz: 33f8f0288db23882f142d42ba7a016c95f06c59bac2930b2252d84f8e4db176c4c614b76162959ba65cdc95cdfe6756a5dec3c4598861b1100c3046cab4d1f5e
7
- data.tar.gz: 4be1f1959ba2dbdd030ee2fbc79b5e641299f10dc686d483f69a85da199985229f044d8e5738bb340c1a8eea8d30626ce01e269af39a36f1c5104a8d0b6d897e
6
+ metadata.gz: 26ae868d09d7989bcacd3362323ea99b31e36dc4cacca293199b11e60be4104f7a4b8156d4f49724bd906c5ad541e665bef5026aa2ed0c1097aa5bd145a34540
7
+ data.tar.gz: 321ecd9a0fd8785475b55f27bf0a495b7056ff64bc7a8d3a2f9841c500ae424b344f13147ca43014cdaf2c5424fcb134b160a208ed1e95e13283f4633332718d
@@ -1,3 +1,4 @@
1
+ require 'protip/version'
1
2
  require 'protip/client'
2
3
  require 'protip/resource'
3
4
 
@@ -69,27 +69,9 @@ module Protip
69
69
  # @param request [Net::HTTPGenericRequest] the raw request object to send
70
70
  # @return [Net::HTTPResponse] the response for the given request
71
71
  def execute_request(request)
72
- http = nil
73
72
  uri = request.uri
74
- retries = 0
75
- max_retries = 3
76
-
77
- begin
78
- unless http
79
- http = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', read_timeout: 120)
80
- end
73
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', read_timeout: 600) do |http|
81
74
  http.request request
82
- rescue Net::OpenTimeout, Net::ReadTimeout
83
- if (retries += 1) <= max_retries
84
- sleep(retries)
85
- retry
86
- else
87
- raise
88
- end
89
- ensure
90
- if http
91
- http.finish
92
- end
93
75
  end
94
76
  end
95
77
  end
@@ -281,7 +281,7 @@ module Protip
281
281
 
282
282
  def method_missing_query(name, *args)
283
283
  field = message.class.descriptor.lookup(name[0, name.length - 1])
284
- raise NoMethodError unless field
284
+ raise NoMethodError.new("No query method found for: #{name}") unless field
285
285
 
286
286
  if nil != Protip::Decorator.enum_for_field(field) && args.length == 1
287
287
  matches?(field, args[0])
@@ -19,7 +19,6 @@ require 'active_model/dirty'
19
19
 
20
20
  require 'forwardable'
21
21
 
22
- require 'protip'
23
22
  require 'protip/client'
24
23
  require 'protip/error'
25
24
  require 'protip/decorator'
@@ -78,14 +77,14 @@ module Protip
78
77
  end
79
78
 
80
79
  def transformer
81
- @transformer || ::Protip.default_transformer
80
+ defined?(@transformer) ? @transformer : ::Protip.default_transformer
82
81
  end
83
82
 
84
83
  private
85
84
 
86
85
  # Primary entry point for defining resourceful behavior.
87
86
  def resource(actions:, message:, query: nil, nested_resources: {})
88
- raise RuntimeError.new('Only one call to `resource` is allowed') if @message
87
+ raise RuntimeError.new('Only one call to `resource` is allowed') if defined?(@message) && @message
89
88
  validate_actions!(actions)
90
89
  validate_nested_resources!(nested_resources)
91
90
 
@@ -338,6 +337,18 @@ module Protip
338
337
  success
339
338
  end
340
339
 
340
+ class RecordInvalid < StandardError
341
+ end
342
+
343
+ def save!
344
+ success = save
345
+ if !success
346
+ error_messages = errors.full_messages.join(", ")
347
+ raise RecordInvalid.new("Validation failed: #{error_messages}")
348
+ end
349
+ success
350
+ end
351
+
341
352
  def persisted?
342
353
  id != nil
343
354
  end
@@ -353,12 +364,5 @@ module Protip
353
364
  def errors
354
365
  @errors ||= ActiveModel::Errors.new(self)
355
366
  end
356
-
357
- private
358
- # needed for ActiveModel::Dirty in earlier ActiveModel versions
359
- def changes_applied
360
- @previously_changed = changes
361
- @changed_attributes.clear
362
- end
363
367
  end
364
368
  end
@@ -1,4 +1,6 @@
1
1
  require 'shellwords'
2
+ require 'bundler/setup'
3
+
2
4
  namespace :protip do
3
5
  desc 'compile a single .proto file to Ruby'
4
6
  task :compile, [:filename, :proto_path, :ruby_path] do |t, args|
@@ -9,7 +11,7 @@ namespace :protip do
9
11
 
10
12
  filename = args[:filename] || raise(ArgumentError.new 'filename argument is required')
11
13
 
12
- command = "grpc_tools_ruby_protoc #{proto_path.map{|p| "--proto_path=#{Shellwords.escape p}"}.join ' '} --ruby_out=#{Shellwords.escape ruby_path} #{Shellwords.escape filename}"
14
+ command = "bundle exec grpc_tools_ruby_protoc #{proto_path.map{|p| "--proto_path=#{Shellwords.escape p}"}.join ' '} --ruby_out=#{Shellwords.escape ruby_path} #{Shellwords.escape filename}"
13
15
  puts command
14
16
  system command
15
17
 
@@ -22,7 +22,7 @@ module Protip
22
22
  if !value.is_a?(::ActiveSupport::TimeWithZone) && (value.is_a?(Time) || value.is_a?(DateTime))
23
23
  value = ::ActiveSupport::TimeWithZone.new(value.to_time.utc, ::ActiveSupport::TimeZone.new('UTC'))
24
24
  end
25
- raise ArgumentError unless value.is_a?(::ActiveSupport::TimeWithZone)
25
+ raise ArgumentError.new("Expected ActiveSupport::TimeWithZone, received #{value.class.name}") unless value.is_a?(::ActiveSupport::TimeWithZone)
26
26
 
27
27
  message_class.new(
28
28
  utc_timestamp: value.to_i,
@@ -32,4 +32,4 @@ module Protip
32
32
  end
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -16,7 +16,7 @@ module Protip
16
16
  end
17
17
 
18
18
  def to_message(object, field)
19
- object = BigDecimal.new(object)
19
+ object = BigDecimal(object)
20
20
  rational = object.to_r
21
21
  field.subtype.msgclass.new(
22
22
  numerator: rational.numerator,
@@ -28,4 +28,4 @@ module Protip
28
28
  end
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -25,7 +25,7 @@ module Protip
25
25
  decorator.assign_attributes(object)
26
26
  decorator.message
27
27
  else
28
- raise ArgumentError
28
+ raise ArgumentError.new("#to_message expected a Hash or an already decorated object, received #{object.class.name} for #{field.type} #{field.name}")
29
29
  end
30
30
  end
31
31
  end
@@ -1,5 +1,6 @@
1
1
  require 'protip/transformer'
2
2
  require 'protip/transformers/abstract_transformer'
3
+ require 'forwardable'
3
4
 
4
5
  module Protip
5
6
  module Transformers
@@ -50,7 +50,7 @@ module Protip
50
50
  ::Date.new(message.year, message.month, message.day)
51
51
  end
52
52
  def to_message(object, field)
53
- raise ArgumentError unless object.is_a?(::Date)
53
+ raise ArgumentError.new("Field #{field.name} expected a date, #{object.class.name} given") unless object.is_a?(::Date)
54
54
  field.subtype.msgclass.new(year: object.year, month: object.month, day: object.day)
55
55
  end
56
56
  end
@@ -77,7 +77,7 @@ module Protip
77
77
  if !object.is_a?(::ActiveSupport::TimeWithZone) && (object.is_a?(Time) || object.is_a?(DateTime))
78
78
  object = ::ActiveSupport::TimeWithZone.new(object.to_time.utc, ::ActiveSupport::TimeZone.new('UTC'))
79
79
  end
80
- raise ArgumentError unless object.is_a?(::ActiveSupport::TimeWithZone)
80
+ raise ArgumentError.new("Expected ActiveSupport::TimeWithZone, received #{object.class.name}") unless object.is_a?(::ActiveSupport::TimeWithZone)
81
81
 
82
82
  field.subtype.msgclass.new(
83
83
  utc_timestamp: object.to_i,
@@ -0,0 +1,3 @@
1
+ module Protip
2
+ VERSION = '0.35.3'
3
+ end
@@ -1,6 +1,7 @@
1
1
  require 'minitest/autorun'
2
- require 'mocha/mini_test'
2
+ require 'mocha/minitest'
3
3
  require 'webmock/minitest'
4
4
  require 'minitest/stub/const'
5
-
6
5
  require 'minitest/pride'
6
+ require 'pry-byebug'
7
+ require 'protip'
@@ -46,7 +46,7 @@ describe Protip::Resource::Associations::BelongsToPolymorphicAssociation do
46
46
  Protip::Resource::Associations::BelongsToPolymorphicAssociation.new resource_class,
47
47
  :reference, [rick_ross_association]
48
48
  end
49
- assert_match /requires an association to be defined/, error.message
49
+ assert_match(/requires an association to be defined/, error.message)
50
50
  end
51
51
 
52
52
  it 'raises an error if a belongs-to association is provided for a field outside the oneof' do
@@ -54,7 +54,7 @@ describe Protip::Resource::Associations::BelongsToPolymorphicAssociation do
54
54
  Protip::Resource::Associations::BelongsToPolymorphicAssociation.new resource_class,
55
55
  :reference, [rick_ross_association, other_association]
56
56
  end
57
- assert_match /requires an association to be defined/, error.message
57
+ assert_match(/requires an association to be defined/, error.message)
58
58
  end
59
59
 
60
60
  it 'raises an error if a duplicate belongs-to association is provided' do
@@ -62,7 +62,7 @@ describe Protip::Resource::Associations::BelongsToPolymorphicAssociation do
62
62
  Protip::Resource::Associations::BelongsToPolymorphicAssociation.new resource_class,
63
63
  :reference, [rick_ross_association, rick_ross_association, fetty_wap_association]
64
64
  end
65
- assert_match /Duplicate association/, error.message
65
+ assert_match(/Duplicate association/, error.message)
66
66
  end
67
67
 
68
68
  it 'allows the oneof ID field to be specified' do
@@ -147,4 +147,4 @@ describe Protip::Resource::Associations::BelongsToPolymorphicAssociation do
147
147
  end
148
148
  end
149
149
  end
150
- end
150
+ end
@@ -1043,7 +1043,7 @@ module Protip::ResourceTest # Namespace for internal constants
1043
1043
  send method, :association_name, bad_option: 'bad', &block
1044
1044
  end
1045
1045
  end
1046
- assert_match /bad_option/, error.message
1046
+ assert_match(/bad_option/, error.message)
1047
1047
  end
1048
1048
  end
1049
1049
  end
@@ -27,14 +27,14 @@ describe Protip::Transformers::BigDecimalTransformer do
27
27
  end
28
28
  end
29
29
  describe 'for BigDecimal arguments' do
30
- it_transforms 'integer', BigDecimal.new(104, 1)
31
- it_transforms 'fractions', BigDecimal.new(100.5, 5)
32
- it_transforms 'rational numbers', BigDecimal.new(Rational(2, 3), 3)
30
+ it_transforms 'integer', BigDecimal(104, 1)
31
+ it_transforms 'fractions', BigDecimal(100.5, 5)
32
+ it_transforms 'rational numbers', BigDecimal(Rational(2, 3), 3)
33
33
  end
34
34
 
35
35
  describe 'for non-BigDecimal arguments' do
36
- it_transforms 'integer', 3, BigDecimal.new(3, 1)
37
- it_transforms 'string', '3.3', BigDecimal.new(3.3, 2)
36
+ it_transforms 'integer', 3, BigDecimal(3, 1)
37
+ it_transforms 'string', '3.3', BigDecimal(3.3, 2)
38
38
 
39
39
  # Match standard BigDecimal behavior for floats
40
40
  it 'raises an argument error for floats' do
@@ -45,4 +45,4 @@ describe Protip::Transformers::BigDecimalTransformer do
45
45
  end
46
46
  end
47
47
  end
48
- end
48
+ end
@@ -5,7 +5,7 @@ require 'protip/transformers/default_transformer'
5
5
  describe Protip::Transformers::DefaultTransformer do
6
6
  describe '#initialize' do
7
7
  it 'initializes without errors' do
8
- transformer = Protip::Transformers::DefaultTransformer.new
8
+ Protip::Transformers::DefaultTransformer.new
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -129,7 +129,7 @@ describe ::Protip::Transformers::PrimitivesTransformer do
129
129
  end
130
130
 
131
131
  it 'raises an exception if non-boolean values passed to a boolean field' do
132
- [nil, 'test', Object.new, 2, {}, []].each do |bad_value|
132
+ ['test', Object.new, 2, {}, []].each do |bad_value|
133
133
  assert_raises TypeError do
134
134
  transformer.to_message(bad_value, field)
135
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.2
4
+ version: 0.35.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - AngelList
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-18 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 4.2.10
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '6.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 3.0.0
29
+ version: 4.2.10
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '6.0'
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 3.0.0
39
+ version: 4.2.10
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '6.0'
@@ -46,24 +46,10 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 3.0.0
49
+ version: 4.2.10
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '6.0'
53
- - !ruby/object:Gem::Dependency
54
- name: google-protobuf
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '3.0'
60
- type: :runtime
61
- prerelease: false
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '3.0'
67
53
  - !ruby/object:Gem::Dependency
68
54
  name: money
69
55
  requirement: !ruby/object:Gem::Requirement
@@ -84,20 +70,34 @@ dependencies:
84
70
  - - "<"
85
71
  - !ruby/object:Gem::Version
86
72
  version: '7.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: google-protobuf
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '='
78
+ - !ruby/object:Gem::Version
79
+ version: 3.6.1
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '='
85
+ - !ruby/object:Gem::Version
86
+ version: 3.6.1
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: grpc-tools
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - "~>"
91
+ - - '='
92
92
  - !ruby/object:Gem::Version
93
- version: '1.0'
93
+ version: 1.3.4
94
94
  type: :development
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - "~>"
98
+ - - '='
99
99
  - !ruby/object:Gem::Version
100
- version: '1.0'
100
+ version: 1.3.4
101
101
  - !ruby/object:Gem::Dependency
102
102
  name: minitest
103
103
  requirement: !ruby/object:Gem::Requirement
@@ -118,84 +118,84 @@ dependencies:
118
118
  requirements:
119
119
  - - "~>"
120
120
  - !ruby/object:Gem::Version
121
- version: '0.5'
121
+ version: '0.6'
122
122
  type: :development
123
123
  prerelease: false
124
124
  version_requirements: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - "~>"
127
127
  - !ruby/object:Gem::Version
128
- version: '0.5'
128
+ version: '0.6'
129
129
  - !ruby/object:Gem::Dependency
130
130
  name: mocha
131
131
  requirement: !ruby/object:Gem::Requirement
132
132
  requirements:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: '1.1'
135
+ version: '1.11'
136
136
  type: :development
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
- version: '1.1'
142
+ version: '1.11'
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: rake
145
145
  requirement: !ruby/object:Gem::Requirement
146
146
  requirements:
147
- - - "~>"
147
+ - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: '10.0'
149
+ version: 12.3.3
150
150
  type: :development
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
153
153
  requirements:
154
- - - "~>"
154
+ - - ">="
155
155
  - !ruby/object:Gem::Version
156
- version: '10.0'
156
+ version: 12.3.3
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: simplecov
159
159
  requirement: !ruby/object:Gem::Requirement
160
160
  requirements:
161
161
  - - "~>"
162
162
  - !ruby/object:Gem::Version
163
- version: '0.10'
163
+ version: '0.18'
164
164
  type: :development
165
165
  prerelease: false
166
166
  version_requirements: !ruby/object:Gem::Requirement
167
167
  requirements:
168
168
  - - "~>"
169
169
  - !ruby/object:Gem::Version
170
- version: '0.10'
170
+ version: '0.18'
171
171
  - !ruby/object:Gem::Dependency
172
- name: pry
172
+ name: pry-byebug
173
173
  requirement: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - "~>"
175
+ - - ">="
176
176
  - !ruby/object:Gem::Version
177
- version: '0.10'
177
+ version: '0'
178
178
  type: :development
179
179
  prerelease: false
180
180
  version_requirements: !ruby/object:Gem::Requirement
181
181
  requirements:
182
- - - "~>"
182
+ - - ">="
183
183
  - !ruby/object:Gem::Version
184
- version: '0.10'
184
+ version: '0'
185
185
  - !ruby/object:Gem::Dependency
186
186
  name: webmock
187
187
  requirement: !ruby/object:Gem::Requirement
188
188
  requirements:
189
189
  - - "~>"
190
190
  - !ruby/object:Gem::Version
191
- version: 3.3.0
191
+ version: '3'
192
192
  type: :development
193
193
  prerelease: false
194
194
  version_requirements: !ruby/object:Gem::Requirement
195
195
  requirements:
196
196
  - - "~>"
197
197
  - !ruby/object:Gem::Version
198
- version: 3.3.0
198
+ version: '3'
199
199
  description:
200
200
  email:
201
201
  - team@angel.co
@@ -255,6 +255,7 @@ files:
255
255
  - lib/protip/transformers/enum_transformer.rb
256
256
  - lib/protip/transformers/primitives_transformer.rb
257
257
  - lib/protip/transformers/timestamp_transformer.rb
258
+ - lib/protip/version.rb
258
259
  - test/functional/protip/decorator_test.rb
259
260
  - test/functional/protip/resource_test.rb
260
261
  - test/test_helper.rb
@@ -291,8 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
292
  - !ruby/object:Gem::Version
292
293
  version: '0'
293
294
  requirements: []
294
- rubyforge_project:
295
- rubygems_version: 2.5.1
295
+ rubygems_version: 3.1.2
296
296
  signing_key:
297
297
  specification_version: 4
298
298
  summary: Resources backed by protobuf messages