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.

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.



30
31
32
33
34
35
36
37
38
39
# File 'lib/cucumber/messages/source.rb', line 30

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



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

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



28
29
30
# File 'lib/cucumber/messages/source.rb', line 28

def media_type
  @media_type
end

#uriObject (readonly)

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



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

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... ...>


48
49
50
51
52
53
54
55
56
# File 'lib/cucumber/messages/source.rb', line 48

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

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