Class: Apipie::Client::Generator
- Inherits:
- 
      Thor::Group
      
        - Object
- Thor::Group
- Apipie::Client::Generator
 
- Includes:
- Thor::Actions
- Defined in:
- lib/apipie/client/generator.rb
Instance Attribute Summary collapse
- 
  
    
      #doc  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute doc. 
- 
  
    
      #resource  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute resource. 
- 
  
    
      #resource_key  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute resource_key. 
Class Method Summary collapse
- .destination_root(name, suffix) ⇒ Object
- .source_root ⇒ Object
- .start(client_name, subject = :all, suffix = '_client', version = nil) ⇒ Object
Instance Method Summary collapse
- #all? ⇒ Boolean
- #generate_cli ⇒ Object
- 
  
    
      #initialize(*args)  ⇒ Generator 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Generator. 
Constructor Details
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
| 22 23 24 | # File 'lib/apipie/client/generator.rb', line 22 def doc @doc end | 
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
| 22 23 24 | # File 'lib/apipie/client/generator.rb', line 22 def resource @resource end | 
#resource_key ⇒ Object (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_root ⇒ Object
| 29 30 31 | # File 'lib/apipie/client/generator.rb', line 29 def self.source_root File.("../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
| 43 44 45 | # File 'lib/apipie/client/generator.rb', line 43 def all? subject == :all end | 
#generate_cli ⇒ Object
| 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 |