Class: Apipie::Client::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/apipie/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.



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

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

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



22
23
24
# File 'lib/apipie/client/generator.rb', line 22

def doc
  @doc
end

#resourceObject (readonly)

Returns the value of attribute resource.



22
23
24
# File 'lib/apipie/client/generator.rb', line 22

def resource
  @resource
end

#resource_keyObject (readonly)

Returns the value of attribute resource_key.



22
23
24
# File 'lib/apipie/client/generator.rb', line 22

def resource_key
  @resource_key
end

Class Method Details

.destination_root(name, suffix) ⇒ Object



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

def self.destination_root(name, suffix)
  File.join(FileUtils.pwd, "#{name}#{suffix}")
end

.source_rootObject



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

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

.start(client_name, subject = :all, suffix = '_client', version = nil) ⇒ Object



37
38
39
40
41
# File 'lib/apipie/client/generator.rb', line 37

def self.start(client_name, subject = :all, suffix = '_client', version = nil)
  name = client_name.parameterize.underscore
  suffix = suffix.parameterize.underscore
  super([name, subject, suffix, version], :destination_root => destination_root(name, suffix))
end

Instance Method Details

#all?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/apipie/client/generator.rb', line 43

def all?
  subject == :all
end

#generate_cliObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/apipie/client/generator.rb', line 47

def generate_cli
  full_name = "#{name}#{suffix}"
  template("README.tt", "README")
  template("Gemfile.tt", "Gemfile")
  template("Rakefile.tt", "Rakefile")
  template("a_name.gemspec.tt", "#{full_name}.gemspec")
  template("lib/a_name.rb.tt", "lib/#{full_name}.rb")
  template("lib/a_name/version.rb.tt", "lib/#{full_name}/version.rb")
  create_file "lib/#{full_name}/documentation.json", JSON.dump(Apipie.to_json)
  copy_file "lib/a_name/config.yml", "lib/#{full_name}/config.yml"
  if all?
    template("bin/bin.rb.tt", "bin/#{full_name}")
    chmod("bin/#{full_name}", 0755)
  end
  doc[:resources].each do |key, resource|
    @resource_key, @resource = key, resource
    if all?
      template("lib/a_name/commands/cli.rb.tt", "lib/#{full_name}/commands/#{resource_name}.thor")
    end
    template("lib/a_name/resources/resource.rb.tt", "lib/#{full_name}/resources/#{resource_name}.rb")
  end
end