Class: Jsonapi::Swagger::Json

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/swagger/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = 'swagger/v1/swagger.json') ⇒ Json

Returns a new instance of Json.



7
8
9
# File 'lib/jsonapi/swagger/json.rb', line 7

def initialize(path = 'swagger/v1/swagger.json')
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/jsonapi/swagger/json.rb', line 5

def path
  @path
end

Instance Method Details

#base_pathObject



15
16
17
# File 'lib/jsonapi/swagger/json.rb', line 15

def base_path
  Jsonapi::Swagger.base_path
end

#loadObject



19
20
21
22
23
24
25
26
# File 'lib/jsonapi/swagger/json.rb', line 19

def load
  @data ||= if File.exist?(path)
            IO.read(path)
          else
            puts "create swagger.json in #{path}"
            '{}'
          end
end

#parse_docObject



11
12
13
# File 'lib/jsonapi/swagger/json.rb', line 11

def parse_doc
  @doc ||= JSON.parse(load) rescue Hash.new{ |h, k| h[k]= {} }
end