Class: JsonStatham::Requests::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/json_statham/requests/base.rb

Direct Known Subclasses

Observer, Reader, Writer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ Base

Returns a new instance of Base.



20
21
22
23
24
25
# File 'lib/json_statham/requests/base.rb', line 20

def initialize(parser)
  Validation.check_object_class(parser, [JsonStatham::Parser])

  @parser = parser
  @config = JsonStatham.config
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



10
11
12
# File 'lib/json_statham/requests/base.rb', line 10

def parser
  @parser
end

Class Method Details

.call(parser) ⇒ Object



16
17
18
# File 'lib/json_statham/requests/base.rb', line 16

def self.call(parser)
  new(parser).call
end

Instance Method Details

#base_pathObject



27
28
29
30
31
# File 'lib/json_statham/requests/base.rb', line 27

def base_path
  return "#{schemas_path}/#{folder_path}" if folder?

  schemas_path
end

#callObject

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/json_statham/requests/base.rb', line 55

def call
  raise NotImplementedError
end

#file_pathObject



37
38
39
# File 'lib/json_statham/requests/base.rb', line 37

def file_path
  "#{base_path}/#{schema_name}.json"
end

#folder?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/json_statham/requests/base.rb', line 33

def folder?
  !!folder_path
end

#folder_pathObject



45
46
47
48
49
# File 'lib/json_statham/requests/base.rb', line 45

def folder_path
  return if splitted_name.length == 1

  splitted_name.reverse.drop(1).reverse.join("/")
end

#schema_nameObject



41
42
43
# File 'lib/json_statham/requests/base.rb', line 41

def schema_name
  splitted_name.last
end

#splitted_nameObject



51
52
53
# File 'lib/json_statham/requests/base.rb', line 51

def splitted_name
  name.split("/")
end