Class: Xnlogic::CLI::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/xnlogic/cli/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, app_name, thor) ⇒ Application

Returns a new instance of Application.



7
8
9
10
11
12
13
14
15
# File 'lib/xnlogic/cli/application.rb', line 7

def initialize(options, app_name, thor)
  @options = options
  @app_name = app_name
  @thor = thor

  @name = app_name.chomp("/").tr('-', '_') # remove trailing slash if present
  @root = options.fetch('root', @name)
  @app = Pathname.pwd.join(root)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/xnlogic/cli/application.rb', line 5

def app
  @app
end

#app_nameObject (readonly)

Returns the value of attribute app_name.



5
6
7
# File 'lib/xnlogic/cli/application.rb', line 5

def app_name
  @app_name
end

#base_nameObject (readonly)

Returns the value of attribute base_name.



5
6
7
# File 'lib/xnlogic/cli/application.rb', line 5

def base_name
  @base_name
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/xnlogic/cli/application.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/xnlogic/cli/application.rb', line 5

def options
  @options
end

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/xnlogic/cli/application.rb', line 5

def root
  @root
end

#thorObject (readonly)

Returns the value of attribute thor.



5
6
7
# File 'lib/xnlogic/cli/application.rb', line 5

def thor
  @thor
end

Instance Method Details

#runObject



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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/xnlogic/cli/application.rb', line 17

def run
  namespaced_path = name
  constant_name = namespaced_path.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join
  git_user_name = `git config user.name`.chomp
  git_user_email = `git config user.email`.chomp

  opts = {
    :name            => name,
    :namespaced_path => namespaced_path,
    :constant_name   => constant_name,
    :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,
    :vm_cpus         => options['cpus'],
    :vm_memory       => options['memory'],
    :xn_key          => options['key'],
  }

  base_templates = {
    "Vagrantfile.tt" => "Vagrantfile",
    "config/vagrant.provision.tt" => "config/vagrant.provision",
    "config/vagrant.settings.yml.tt" => "config/vagrant.settings.yml",
    "config/datomic.conf" => "config/datomic.conf",
    "config/transactor.properties" => "config/transactor.properties",
  }

  base_templates.each do |src, dst|
    thor.template("vagrant/#{src}", app.join(dst), opts)
  end

  templates = {
    "gitignore.tt" => ".gitignore",
    ".rspec.tt" => ".rspec",
    "Gemfile.tt" => "Gemfile",
    "Readme.md.tt" => "Readme.md",
    "config.ru.tt" => "config.ru",
    "dev/console.rb.tt" => "dev/console.rb",
    "torquebox.yml.tt" => "torquebox.yml",
    "torquebox_init.rb.tt" => "torquebox_init.rb",
    "lib/gemname.rb.tt" => "lib/#{namespaced_path}.rb",
    "lib/gemname/version.rb.tt" => "lib/#{namespaced_path}/version.rb",
    "lib/gemname/initializers/inflections.rb.tt" => "lib/#{namespaced_path}/initializers/inflections.rb",
    "lib/gemname/parts/has_notes.rb.tt" => "lib/#{namespaced_path}/parts/has_notes.rb",
    "lib/gemname/parts/note.rb.tt" => "lib/#{namespaced_path}/parts/note.rb",
    "lib/gemname/type/url.rb.tt" => "lib/#{namespaced_path}/type/url.rb",
    "lib/gemname/fixtures.rb.tt" => "lib/#{namespaced_path}/fixtures.rb",
    "lib/gemname/models.rb.tt" => "lib/#{namespaced_path}/models.rb",
    "lib/gemname/permissions.rb.tt" => "lib/#{namespaced_path}/permissions.rb",
    "lib/gemname/type.rb.tt" => "lib/#{namespaced_path}/type.rb",
    "lib/fixtures/sample_fixtures.rb.tt" => "lib/fixtures/sample_fixtures.rb",

    "spec/spec_helper.rb.tt" => "spec/spec_helper.rb",
    "spec/gemname/gemname_spec.rb.tt" => "spec/#{namespaced_path}/#{name}_spec.rb",
  }

  templates.each do |src, dst|
    thor.template("application/#{src}", app.join(dst), opts)
  end

  Xnlogic.ui.info "Creating Vagrant config."
  Xnlogic.ui.info ""
  Xnlogic.ui.info "Initializing git repo in #{app}"
  Dir.chdir(app) { `git init`; `git add .` }

  Xnlogic.ui.info ""
  Xnlogic.ui.info "Please ensure that the following dependencies are installed on your computer"
  Xnlogic.ui.info "to continue."
  Xnlogic.ui.info " - Vagrant:    https://www.vagrantup.com/"
  Xnlogic.ui.info " - VirtualBox: https://www.virtualbox.org/wiki/Downloads"
  Xnlogic.ui.info ""
  Xnlogic.ui.info "Then run the following:"
  Xnlogic.ui.info ""
  Xnlogic.ui.info "cd #{root}"
  Xnlogic.ui.info "vagrant up"
  Xnlogic.ui.info "vagrant ssh"
  Xnlogic.ui.info ""
  Xnlogic.ui.info "Once logged in to the server, the project directory is ~/xn.dev"
end