cucumber-messages 33.0.1 → 33.0.3

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: c8603b286ae6baa361e441627edb67af2cc47dd8d976382047ab739412adb35f
4
- data.tar.gz: 1c59a1db30d3567f1690c59d3d5762c2d2aa5c92aff34a9c8adfa9d7b7535d81
3
+ metadata.gz: ebfbb934be415f5579944c4b44c4dc07ef7fde6a283e36d4de17d6cc8619b2a3
4
+ data.tar.gz: c2699843f6c5685e209fc51333977c71603e0fe28089c25dd296d53a7fb6df9b
5
5
  SHA512:
6
- metadata.gz: e42afd64f7984b917f79bbc47cb18ba0384da160051f521fecf2f375b391749374e2e26370af0dcb1c09a52f027bc345276d1e98d1205810c7bc038415b99f57
7
- data.tar.gz: 92621fac365f8c42111f6c8fd74900c47d2f71ac91e96cd610bc491a01b02f020ba79945dcf9080c753df7ecc9a93cd204c6be67bdead2511bfe434c19382092
6
+ metadata.gz: '0309d95a3f3770cc347c8003dd9d88819b170d70407779bdd884b3040ffa100d2614a253fd598b1ef37fc27c8eee149066ff863be852e6b5b830a2698f546e5f'
7
+ data.tar.gz: d5523a5d07a06a3b6ddfb62ebb7f414ea5d01a5187ceff592183caaf37886cb11fb013621057481dd6d8319b68e21a7a1726530d5a3a32f95c9841ae0c36ff16
data/VERSION CHANGED
@@ -1 +1 @@
1
- 33.0.1
1
+ 33.0.3
@@ -67,22 +67,48 @@ module Cucumber
67
67
  # Keys are camelized during the process. Null values are not part of the json document.
68
68
  #
69
69
  # Cucumber::Messages::Duration.new(seconds: 1, nanos: 42).to_json
70
- # # => '{"seconds":1,"nanos":42}'
70
+ # # => {"seconds":1,"nanos":42}
71
71
  # Cucumber::Messages::PickleTag.new(name: 'foo', ast_node_id: 'abc-def').to_json
72
- # # => '{"name":"foo","astNodeId":"abc-def"}'
72
+ # # => {"name":"foo","astNodeId":"abc-def"}
73
73
  # Cucumber::Messages::PickleTag.new(name: 'foo', ast_node_id: nil).to_json
74
- # # => '{"name":"foo"}'
74
+ # # => {"name":"foo"}
75
75
  #
76
76
  # As with #to_h, the method is recursive
77
77
  #
78
78
  # location = Cucumber::Messages::Location.new(line: 2)
79
79
  # Cucumber::Messages::Comment.new(location: location, text: 'comment').to_json
80
- # # => '{"location":{"line":2,"column":null},"text":"comment"}'
80
+ # # => {"location":{"line":2,"column":null},"text":"comment"}
81
81
  ##
82
82
  def to_json(*_args)
83
83
  to_h(camelize: true, reject_nil_values: true).to_json
84
84
  end
85
85
 
86
+ ##
87
+ # Returns the type of the message as a hash with snake_cased symbols.
88
+ # For example, the type of a `Cucumber::Messages::Duration` will be `:duration`.
89
+ #
90
+ # Cucumber::Messages::Duration.new(seconds: 1, nanos: 42).type
91
+ # # => { type: :duration }
92
+ # Cucumber::Messages::PickleTag.new(name: 'foo', ast_node_id: 'abc-def').type
93
+ # # => { type: :pickle_tag }
94
+ #
95
+ # For Envelopes, the hash will return the type as `:envelope` but it will also indicate the nested envelope message
96
+ #
97
+ # location = Cucumber::Messages::Location.new(line: 2)
98
+ # Cucumber::Messages::Envelope.new(location: location).type
99
+ # # => { type: :envelope, contained_message: :location }
100
+ ##
101
+ def type
102
+ if is_a?(Cucumber::Messages::Envelope)
103
+ {
104
+ type: :envelope,
105
+ contained_message: unwrapped_envelope_type
106
+ }
107
+ else
108
+ { type: underscore(self.class.to_s.split('::').last).to_sym }
109
+ end
110
+ end
111
+
86
112
  private
87
113
 
88
114
  def prepare_value(value, camelize:, reject_nil_values:)
@@ -94,6 +120,21 @@ module Cucumber
94
120
  value
95
121
  end
96
122
  end
123
+
124
+ # Simplified form of `TextHelpers` generator module
125
+ def underscore(klazz_name)
126
+ klazz_name.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
127
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
128
+ .downcase
129
+ end
130
+
131
+ # This will scan each iVar and return the first one (Should only ever be one), that is not nil
132
+ def unwrapped_envelope_type
133
+ instance_variables.detect { |name| !instance_variable_get(name).nil? }
134
+ .to_s
135
+ .delete_prefix('@')
136
+ .to_sym
137
+ end
97
138
  end
98
139
  end
99
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-messages
3
3
  version: !ruby/object:Gem::Version
4
- version: 33.0.1
4
+ version: 33.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy
@@ -203,5 +203,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  requirements: []
204
204
  rubygems_version: 4.0.10
205
205
  specification_version: 4
206
- summary: cucumber-messages-33.0.1
206
+ summary: cucumber-messages-33.0.3
207
207
  test_files: []