Class: KatelloApi::Generator::Base

Inherits:
Thor::Group
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper, Thor::Actions
Defined in:
lib/katello_api/generator/base.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize(doc, *args)

Returns a new instance of Base



25
26
27
28
# File 'lib/katello_api/generator/base.rb', line 25

def initialize(doc, *args)
  super
  @doc = doc.first
end

Instance Attribute Details

- (Object) doc (readonly)

Returns the value of attribute doc



23
24
25
# File 'lib/katello_api/generator/base.rb', line 23

def doc
  @doc
end

- (Object) resource (readonly)

Returns the value of attribute resource



23
24
25
# File 'lib/katello_api/generator/base.rb', line 23

def resource
  @resource
end

- (Object) resource_key (readonly)

Returns the value of attribute resource_key



23
24
25
# File 'lib/katello_api/generator/base.rb', line 23

def resource_key
  @resource_key
end

Class Method Details

+ (Object) source_root



30
31
32
# File 'lib/katello_api/generator/base.rb', line 30

def self.source_root
  File.expand_path("../template", __FILE__)
end

+ (Object) start(katello_url, api_version = nil)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/katello_api/generator/base.rb', line 34

def self.start(katello_url, api_version = nil)
  katello_url = katello_url.sub(/\.json\Z/,"")
  katello_url << "/#{(api_version || KatelloApi::Base::API_VERSION)}.json"
  uri = URI(katello_url)
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == "https"
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  response = http.get(uri.path)

  unless response.code == "200"
    raise "Could not load data from #{katello_url}"
  end
  body = response.body
  File.open(KatelloApi.doc_file, "w") { |f| f.write(body) }
  doc = JSON.load(body).with_indifferent_access
  destination = File.expand_path("../../../..", __FILE__)
  super([doc[:docs]], :destination_root => destination)
end

Instance Method Details

- (Object) generate



55
56
57
58
59
60
# File 'lib/katello_api/generator/base.rb', line 55

def generate
  doc[:resources].each do |key, resource|
    @resource_key, @resource = key, resource
    template("resource.rb.tt", "lib/katello_api/resources/#{resource_name}.rb")
  end
end