Class: Harbor::Generator::SetupCommand
- Inherits:
-
Object
- Object
- Harbor::Generator::SetupCommand
- Defined in:
- lib/harbor/generator/setup.rb
Constant Summary collapse
- HELP =
<<-HELP Usage: harbor setup app_name Sets up a new Harbor port using the conventional directory structure. The application can be booted using your server of choice: > rackup # http://localhost:9292/ > unicorn # http://localhost:8080/ > thin -R config.ru start # http://localhost:3000/ HELP
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
Instance Method Summary collapse
- #app_class ⇒ Object
-
#initialize(options) ⇒ SetupCommand
constructor
A new instance of SetupCommand.
- #log(action, message) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ SetupCommand
Returns a new instance of SetupCommand.
23 24 25 26 27 28 29 30 |
# File 'lib/harbor/generator/setup.rb', line 23 def initialize() @app_name = .first unless @app_name puts HELP exit(1) end end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
21 22 23 |
# File 'lib/harbor/generator/setup.rb', line 21 def app_name @app_name end |
Instance Method Details
#app_class ⇒ Object
74 75 76 77 78 |
# File 'lib/harbor/generator/setup.rb', line 74 def app_class # 'sample' => 'Sample' # 'cool_app' => 'CoolApp' @app_name.gsub(/(^|-|_)[a-z0-9]{1}/) { |m| m.sub(/-|_/, '').upcase } end |
#log(action, message) ⇒ Object
32 33 34 |
# File 'lib/harbor/generator/setup.rb', line 32 def log(action, ) puts "%12s %s" % [action, ] end |
#run ⇒ Object
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 |
# File 'lib/harbor/generator/setup.rb', line 36 def run unless File.exists?(@app_name) log("create", @app_name) `mkdir #{@app_name}` end skeleton_path = Pathname(__FILE__).dirname + 'skeletons/basic' Dir[skeleton_path + "**/*"].each do |item| item = Pathname(item) relative_path = "#{@app_name}/#{item.relative_path_from(skeleton_path)}" relative_path.sub!("appname", @app_name) if File.exists?(relative_path.sub(/\.skel$/, "")) log("exists", relative_path.sub(/\.skel$/, "")) next end if item.directory? log("create", relative_path) `mkdir #{relative_path}` elsif relative_path.sub!(/\.skel$/, "") log("create", relative_path) ::File.open(relative_path, 'w') do |file| file.puts Erubis::FastEruby.new(::File.read(item), :pattern => '##> <##').evaluate(self) end else log("create", relative_path) FileUtils.cp(item, relative_path) end end `chmod +x #{@app_name}/config.ru` end |