Class: Otis::Generator::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/otis/generator/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



7
8
9
# File 'lib/otis/generator/cli.rb', line 7

def self.source_root
  File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
end

Instance Method Details

#generateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/otis/generator/cli.rb', line 15

def generate
  wsdl = options[:wsdl]
  n = name
  name = n.chomp("/") # remove trailing slash if present
  unless wsdl
    puts "You did not provide any WSDL file. Sorry, I can't guess the structure of the webservice without it!"
    puts "Bye."
    exit
  end
  routes = routes(wsdl)

  generate_soap(name, routes)

  namespaced_path = name.tr('-', '/')
  target = File.join(Dir.pwd, name)
  create_config(target, wsdl)

  constant_name = constantize(name)
  constant_array = constant_name.split('::')
  git_user_name = `git config user.name`.chomp
  git_user_email = `git config user.email`.chomp
  opts = {
    :name            => name,
    :models          => routes.keys,
    :namespaced_path => namespaced_path,
    :constant_name   => constant_name,
    :routes          =>  Otis::Generator::RoutesPresenter.new(routes),
    :wsdl            => wsdl,
    :constant_array  => constant_array,
    :author          => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
    :email           => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
    :test            => options[:test]
  }

  gemspec_dest = File.join(target, "#{name}.gemspec")
  template(File.join("newgem/Gemfile.tt"),               File.join(target, "Gemfile"),                             opts)
  template(File.join("newgem/Rakefile.tt"),              File.join(target, "Rakefile"),                            opts)
  template(File.join("newgem/LICENSE.txt.tt"),           File.join(target, "LICENSE.txt"),                         opts)
  template(File.join("newgem/README.md.tt"),             File.join(target, "README.md"),                           opts)
  template(File.join("newgem/gitignore.tt"),             File.join(target, ".gitignore"),                          opts)
  template(File.join("newgem/newgem.gemspec.tt"),        gemspec_dest,                                             opts)
  template(File.join("newgem/lib/newgem.rb.tt"),         File.join(target, "lib/#{namespaced_path}.rb"),           opts)
  template(File.join("newgem/lib/newgem/version.rb.tt"), File.join(target, "lib/#{namespaced_path}/version.rb"),   opts)

  template(File.join("newgem/rspec.tt"),               File.join(target, ".rspec"),                              opts)
  template(File.join("newgem/spec/spec_helper.rb.tt"), File.join(target, "spec/spec_helper.rb"),                 opts)
  template(File.join("newgem/spec/newgem_spec.rb.tt"), File.join(target, "spec/#{namespaced_path}/#{namespaced_path}_spec.rb"),     opts)
  template(File.join("newgem/spec/integration/newgem_integration_spec.tt"), File.join(target, "spec/integration/#{namespaced_path}_integration_spec.rb"),     opts)

  Dir.chdir(target) { `git init`; `git add .` }
end