Class: Restapi::Client::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/restapi/client/generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Generator

Returns a new instance of Generator.



20
21
22
23
# File 'lib/restapi/client/generator.rb', line 20

def initialize(*args)
  super
  @doc = Restapi.to_json()[:docs]
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



18
19
20
# File 'lib/restapi/client/generator.rb', line 18

def doc
  @doc
end

#resourceObject (readonly)

Returns the value of attribute resource.



18
19
20
# File 'lib/restapi/client/generator.rb', line 18

def resource
  @resource
end

Class Method Details

.destination_rootObject



29
30
31
# File 'lib/restapi/client/generator.rb', line 29

def self.destination_root
  File.join(FileUtils.pwd, "client")
end

.source_rootObject



25
26
27
# File 'lib/restapi/client/generator.rb', line 25

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

.start(client_name) ⇒ Object



33
34
35
# File 'lib/restapi/client/generator.rb', line 33

def self.start(client_name)
  super([client_name.parameterize.underscore], :destination_root => destination_root)
end

Instance Method Details

#generate_cliObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/restapi/client/generator.rb', line 37

def generate_cli
  template("README.tt", "README")
  template("Gemfile.tt", "Gemfile")
  template("bin.rb.tt", "bin/#{name}-client")
  chmod("bin/#{name}-client", 0755)
  template("client.rb.tt", "lib/#{name}_client.rb")
  template("base.rb.tt", "lib/#{name}_client/base.rb")
  template("cli_command.rb.tt", "lib/#{name}_client/cli_command.rb")
  doc[:resources].each do |key, resource|
    @resource = resource
    template("cli.rb.tt", "lib/#{name}_client/commands/#{resource_name}.thor")
    template("resource.rb.tt", "lib/#{name}_client/resources/#{resource_name}.rb")
  end
end