Class: Shaf::Parser::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/shaf/parser/base.rb

Direct Known Subclasses

FormData, Json

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request:, body:) ⇒ Base

Returns a new instance of Base.



27
28
29
30
# File 'lib/shaf/parser/base.rb', line 27

def initialize(request:, body:)
  @request = request
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



25
26
27
# File 'lib/shaf/parser/base.rb', line 25

def body
  @body
end

#requestObject (readonly)

Returns the value of attribute request.



25
26
27
# File 'lib/shaf/parser/base.rb', line 25

def request
  @request
end

Class Method Details

.can_handle?(request) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/shaf/parser/base.rb', line 19

def can_handle?(request)
  mime_type == request.content_type
end

.inherited(child) ⇒ Object



5
6
7
8
# File 'lib/shaf/parser/base.rb', line 5

def inherited(child)
  Parser.register(child)
  super
end

.mime_type(type = nil, value = nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/shaf/parser/base.rb', line 10

def mime_type(type = nil, value = nil)
  if type
    @mime_type = type
    @mime_type = Sinatra::Base.mime_type(type, value) if type.is_a? Symbol
  end

  @mime_type if defined? @mime_type
end

Instance Method Details

#callObject

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/shaf/parser/base.rb', line 32

def call
  raise NotImplementedError, "#{self.class} must implement #call"
end