protip 0.13.0 → 0.13.1

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: 1170fab1e59f11eaf4e5d9fa6180d7086e5fe5fc
4
- data.tar.gz: dece3a11f6abd2f216e78ee7df65245b03dd1c55
3
+ metadata.gz: 23c197f44c8f1c1812859e1e7567fb8d0dde9ffb
4
+ data.tar.gz: 45a759374549ebbe818e89fc958adaf47d199a8c
5
5
  SHA512:
6
- metadata.gz: 07f0f92583e771802269412f33d383bcf878d35939b97906db016fa8c3af12500bdcffe9a5eb6545233f4cbfc878c2a842a01db66d54a8463ec2b18a45080684
7
- data.tar.gz: dfaf66f2608d722e89b64bbbf144c12d36e788205e69431c528e7678507f487419a50c90e061a6fadc55d1eee5163e02e5a0acb5eb5a6675cc77c7f458e6cdf6
6
+ metadata.gz: 7e384ce1be77a5c0eb22052762da2ae105f3b0748025017ed4045db83a663e8ec3620b473a7ca2176b82e1d18685d075d5145bb8d99f17e7705f9d01c0a63f0c
7
+ data.tar.gz: 1cd15cd584f2d42d8fd5f44205157a6e933dfebda42758ff8ea0c9e2892d2fdec147e397c007763474b9a3a73277a075a978a51e9ed7cef51a5810c4c73aec20
@@ -32,8 +32,15 @@ module Protip
32
32
  assign_attributes attributes
33
33
  args[0] # return the input value (to match ActiveRecord behavior)
34
34
  elsif (name =~ /\?$/ && field = message.class.descriptor.detect{|field| self.class.matchable?(field) && :"#{field.name}?" == name})
35
- raise ArgumentError unless args.length == 1
36
- matches? field, args[0]
35
+ if args.length == 1
36
+ # this is an enum query, e.g. `state?(:CREATED)`
37
+ matches? field, args[0]
38
+ elsif args.length == 0
39
+ # this is a boolean query, e.g. `approved?`
40
+ get field
41
+ else
42
+ raise ArgumentError
43
+ end
37
44
  elsif (field = message.class.descriptor.detect{|field| field.name.to_sym == name})
38
45
  raise ArgumentError unless args.length == 0
39
46
  get field
@@ -146,7 +153,11 @@ module Protip
146
153
  # Semi-private check for whether a field should have an associated query method (e.g. +field_name?+).
147
154
  # @return [Boolean] Whether the field should have an associated query method on wrappers.
148
155
  def matchable?(field)
149
- field.type == :enum && field.label != :repeated
156
+ return false if field.label == :repeated
157
+
158
+ field.type == :enum ||
159
+ field.type == :bool ||
160
+ field.type == :message && (field.subtype.name == "google.protobuf.BoolValue")
150
161
  end
151
162
  end
152
163
 
@@ -16,6 +16,9 @@ module Protip::ResourceTest # Namespace for internal constants
16
16
  add_message 'nested_message' do
17
17
  optional :number, :int64, 1
18
18
  end
19
+ add_message "google.protobuf.BoolValue" do
20
+ optional :value, :bool, 1
21
+ end
19
22
  add_message 'resource_message' do
20
23
  optional :id, :int64, 1
21
24
  optional :string, :string, 2
@@ -23,6 +26,10 @@ module Protip::ResourceTest # Namespace for internal constants
23
26
  optional :nested_message, :message, 4, 'nested_message'
24
27
  optional :number, :enum, 5, 'number'
25
28
  repeated :numbers, :enum, 6, 'number'
29
+ optional :boolean, :bool, 8
30
+ repeated :booleans, :bool, 9
31
+ optional :google_bool_value, :message, 10, "google.protobuf.BoolValue"
32
+ repeated :google_bool_values, :message, 11, "google.protobuf.BoolValue"
26
33
  end
27
34
 
28
35
  add_message 'resource_query' do
@@ -139,6 +146,16 @@ module Protip::ResourceTest # Namespace for internal constants
139
146
  refute resource.number?(:ONE)
140
147
  end
141
148
 
149
+ it 'defines query methods for the booleans on its message' do
150
+ assert_respond_to resource, :boolean?
151
+ refute resource.boolean?
152
+ end
153
+
154
+ it 'defines query methods for the google.protobuf.BoolValues on its message' do
155
+ assert_respond_to resource, :google_bool_value?
156
+ refute resource.google_bool_value?
157
+ end
158
+
142
159
  it 'does not define query methods for repeated enums' do
143
160
  refute_respond_to resource, :numbers?
144
161
  assert_raises NoMethodError do
@@ -23,6 +23,9 @@ module Protip::WrapperTest # namespace for internal constants
23
23
  optional :value, :int64, 1
24
24
  optional :note, :string, 2
25
25
  end
26
+ add_message "google.protobuf.BoolValue" do
27
+ optional :value, :bool, 1
28
+ end
26
29
 
27
30
  add_message 'message' do
28
31
  optional :inner, :message, 1, 'inner_message'
@@ -35,6 +38,12 @@ module Protip::WrapperTest # namespace for internal constants
35
38
 
36
39
  optional :number, :enum, 6, 'number'
37
40
  repeated :numbers, :enum, 7, 'number'
41
+
42
+ optional :boolean, :bool, 8
43
+ repeated :booleans, :bool, 9
44
+
45
+ optional :google_bool_value, :message, 10, "google.protobuf.BoolValue"
46
+ repeated :google_bool_values, :message, 11, "google.protobuf.BoolValue"
38
47
  end
39
48
  end
40
49
  pool
@@ -65,13 +74,17 @@ module Protip::WrapperTest # namespace for internal constants
65
74
  assert_respond_to wrapper, :inner
66
75
  assert_respond_to wrapper, :inner_blank
67
76
  end
68
- it 'adds queries for scalar enum fields' do
69
- assert_respond_to wrapper, :number?
77
+ it 'adds queries for scalar matchable fields' do
78
+ assert_respond_to wrapper, :number?, 'enum field should respond to query'
79
+ assert_respond_to wrapper, :boolean?, 'bool field should respond to query'
80
+ assert_respond_to wrapper, :google_bool_value?, 'google.protobuf.BoolValue field should respond to query'
70
81
  end
71
- it 'does not add queries for repeated enum fields' do
72
- refute_respond_to wrapper, :numbers?
82
+ it 'does not add queries for repeated fields' do
83
+ refute_respond_to wrapper, :numbers?, 'repeated enum field should not respond to query'
84
+ refute_respond_to wrapper, :booleans?, 'repeated bool field should not respond to query'
85
+ refute_respond_to wrapper, :google_bool_values?, 'repeated google.protobuf.BoolValue field should not respond to query'
73
86
  end
74
- it 'does not add queries for non-enum fields' do
87
+ it 'does not add queries for non-matchable fields' do
75
88
  refute_respond_to wrapper, :inner?
76
89
  end
77
90
  it 'responds to standard defined methods' do
@@ -300,7 +313,7 @@ module Protip::WrapperTest # namespace for internal constants
300
313
  end
301
314
 
302
315
  it 'contains keys for all fields of the parent message' do
303
- assert_equal %i(string strings inner inners inner_blank number numbers).sort, wrapper.to_h.keys.sort
316
+ assert_equal %i(string strings inner inners inner_blank number numbers boolean booleans google_bool_value google_bool_values).sort, wrapper.to_h.keys.sort
304
317
  end
305
318
  it 'assigns nil for missing nested messages' do
306
319
  hash = wrapper.to_h
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.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - AngelList
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-22 00:00:00.000000000 Z
11
+ date: 2015-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel