Class: Genio::Parser::Format::Base

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/genio/parser/format/base.rb

Direct Known Subclasses

IODocs, JsonSchema, Wadl

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



29
30
31
32
33
34
35
36
# File 'lib/genio/parser/format/base.rb', line 29

def initialize(options = {})
  @options = options

  @files      = Types::Base.new( "#" => "self" )
  @services   = Types::Base.new
  @data_types = Types::Base.new
  @enum_types = Types::Base.new
end

Instance Attribute Details

#data_typesObject

Returns the value of attribute data_types.



27
28
29
# File 'lib/genio/parser/format/base.rb', line 27

def data_types
  @data_types
end

#endpointObject

Returns the value of attribute endpoint.



27
28
29
# File 'lib/genio/parser/format/base.rb', line 27

def endpoint
  @endpoint
end

#enum_typesObject

Returns the value of attribute enum_types.



27
28
29
# File 'lib/genio/parser/format/base.rb', line 27

def enum_types
  @enum_types
end

#filesObject

Returns the value of attribute files.



27
28
29
# File 'lib/genio/parser/format/base.rb', line 27

def files
  @files
end

#optionsObject

Returns the value of attribute options.



27
28
29
# File 'lib/genio/parser/format/base.rb', line 27

def options
  @options
end

#servicesObject

Returns the value of attribute services.



27
28
29
# File 'lib/genio/parser/format/base.rb', line 27

def services
  @services
end

Instance Method Details

#expand_path(file) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/genio/parser/format/base.rb', line 51

def expand_path(file)
  if load_files.any? and file !~ /^(\/|https?:\/\/)/
    parent_file = load_files.last
    if parent_file =~ /^https?:/
      file = URI.join(parent_file, file).to_s
    else
      file = File.expand_path(file, File.dirname(parent_file))
    end
  end
  file
end

#load_filesObject



47
48
49
# File 'lib/genio/parser/format/base.rb', line 47

def load_files
  @load_files ||= []
end

#open(file, options = {}) ⇒ Object



42
43
44
45
# File 'lib/genio/parser/format/base.rb', line 42

def open(file, options = {})
  options[:ssl_verify_mode] ||= 0
  super(file, options)
end

#read_file(file, &block) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/genio/parser/format/base.rb', line 63

def read_file(file, &block)
  file = expand_path(file)
  load_files.push(file)
  logger.info("GET #{file}")
  block.call(open(file).read)
ensure
  load_files.pop
end

#to_iodocsObject



38
39
40
# File 'lib/genio/parser/format/base.rb', line 38

def to_iodocs
  IODocs.to_iodocs(self)
end