Class: RailsHttpLab::Bruno::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_http_lab/bruno/document.rb

Constant Summary collapse

VERBS =
%w[get post put patch delete head options].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blocks: [], leading_blank_lines: 0, trailing_newline: true) ⇒ Document

Returns a new instance of Document.



7
8
9
10
11
# File 'lib/rails_http_lab/bruno/document.rb', line 7

def initialize(blocks: [], leading_blank_lines: 0, trailing_newline: true)
  @blocks              = blocks
  @leading_blank_lines = leading_blank_lines
  @trailing_newline    = trailing_newline
end

Instance Attribute Details

#blocksObject

Returns the value of attribute blocks.



4
5
6
# File 'lib/rails_http_lab/bruno/document.rb', line 4

def blocks
  @blocks
end

#leading_blank_linesObject

Returns the value of attribute leading_blank_lines.



5
6
7
# File 'lib/rails_http_lab/bruno/document.rb', line 5

def leading_blank_lines
  @leading_blank_lines
end

#trailing_newlineObject

Returns the value of attribute trailing_newline.



5
6
7
# File 'lib/rails_http_lab/bruno/document.rb', line 5

def trailing_newline
  @trailing_newline
end

Instance Method Details

#block(name) ⇒ Object



13
14
15
# File 'lib/rails_http_lab/bruno/document.rb', line 13

def block(name)
  blocks.find { |b| b.name == name }
end

#blocks_named(name) ⇒ Object



17
18
19
# File 'lib/rails_http_lab/bruno/document.rb', line 17

def blocks_named(name)
  blocks.select { |b| b.name == name }
end

#http_methodObject



27
28
29
# File 'lib/rails_http_lab/bruno/document.rb', line 27

def http_method
  verb_block&.name&.upcase
end

#urlObject



31
32
33
# File 'lib/rails_http_lab/bruno/document.rb', line 31

def url
  verb_block&.[]("url")
end

#verb_blockObject



23
24
25
# File 'lib/rails_http_lab/bruno/document.rb', line 23

def verb_block
  blocks.find { |b| VERBS.include?(b.name) }
end