Class: Cucumber::Messages::Snippet

Inherits:
Message
  • Object
show all
Defined in:
lib/cucumber/messages/snippet.rb

Overview

Represents the Snippet message in Cucumber’s message protocol.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

camelize, from_json, #to_h, #to_json

Constructor Details

#initialize(language: '', code: '') ⇒ Snippet

Returns a new instance of Snippet.



24
25
26
27
28
29
30
31
# File 'lib/cucumber/messages/snippet.rb', line 24

def initialize(
  language: '',
  code: ''
)
  @language = language
  @code = code
  super()
end

Instance Attribute Details

#codeObject (readonly)

A snippet of code



22
23
24
# File 'lib/cucumber/messages/snippet.rb', line 22

def code
  @code
end

#languageObject (readonly)

The programming language of the code.

This must be formatted as an all lowercase identifier such that syntax highlighters like [Prism](prismjs.com/#supported-languages) or [Highlight.js](github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md) can recognize it. For example: ‘cpp`, `cs`, `go`, `java`, `javascript`, `php`, `python`, `ruby`, `scala`.



17
18
19
# File 'lib/cucumber/messages/snippet.rb', line 17

def language
  @language
end

Class Method Details

.from_h(hash) ⇒ Object

Returns a new Snippet from the given hash. If the hash keys are camelCased, they are properly assigned to the corresponding snake_cased attributes.

Cucumber::Messages::Snippet.from_h(some_hash) # => #<Cucumber::Messages::Snippet:0x... ...>


40
41
42
43
44
45
46
47
# File 'lib/cucumber/messages/snippet.rb', line 40

def self.from_h(hash)
  return nil if hash.nil?

  new(
    language: hash[:language],
    code: hash[:code]
  )
end