Class: Cucumber::Messages::Source

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

Overview

Represents the Source message in Cucumber’s message protocol.

//// Source

*

A source file, typically a Gherkin document or Java/Ruby/JavaScript source code

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(uri: '', data: '', media_type: SourceMediaType::TEXT_X_CUCUMBER_GHERKIN_PLAIN) ⇒ Source

Returns a new instance of Source.



34
35
36
37
38
39
40
41
42
43
# File 'lib/cucumber/messages/source.rb', line 34

def initialize(
  uri: '',
  data: '',
  media_type: SourceMediaType::TEXT_X_CUCUMBER_GHERKIN_PLAIN
)
  @uri = uri
  @data = data
  @media_type = media_type
  super()
end

Instance Attribute Details

#dataObject (readonly)

The contents of the file



26
27
28
# File 'lib/cucumber/messages/source.rb', line 26

def data
  @data
end

#media_typeObject (readonly)

The media type of the file. Can be used to specify custom types, such as

text/x.cucumber.gherkin+plain


32
33
34
# File 'lib/cucumber/messages/source.rb', line 32

def media_type
  @media_type
end

#uriObject (readonly)

*

The [URI](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)
of the source, typically a file path relative to the root directory


21
22
23
# File 'lib/cucumber/messages/source.rb', line 21

def uri
  @uri
end

Class Method Details

.from_h(hash) ⇒ Object

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

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


52
53
54
55
56
57
58
59
60
# File 'lib/cucumber/messages/source.rb', line 52

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

  new(
    uri: hash[:uri],
    data: hash[:data],
    media_type: hash[:mediaType]
  )
end