Class: Ickgg::Command

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/ickgg/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



8
9
10
# File 'lib/ickgg/command.rb', line 8

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#cObject



72
73
74
75
76
77
78
79
# File 'lib/ickgg/command.rb', line 72

def c
  puts "starting console ..."
  require "pry"
  require "awesome_print"
  require "./script/server"
  Pry.start
  puts ""
end

#g(g_type, g_name, *args) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ickgg/command.rb', line 82

def g g_type, g_name, *args
  @entity_name = g_name.include?("_") ? g_name.split("_").first : g_name
  @class_name = g_name.camelize
  case g_type
  when "entity"
    generate_entity g_name, args
  when "api"
    @resources_symbol = g_name.to_sym
    generate_api g_name, args
  else
    puts "invalid generator type"
  end
end

#new(app_name) ⇒ Object



14
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
# File 'lib/ickgg/command.rb', line 14

def new app_name
  @app_name = app_name.capitalize
  say "create a new application named #{app_name}", :green

  # create folder structure
  %w{app app/apis app/helpers app/entities app/models config config/environments config/initializers script log tmp lib spec spec/apis spec/entities spec/helpers}.each do |item|
    empty_directory app_name + "/" + item
  end


  # create basic files
  {
    application: "config/application.rb",
    database: "config/database.yml",
    redis: "config/redis.yml",
    spec_helper: "spec/spec_helper.rb",
    gemfile: "Gemfile",  
    # guardfile: "Guardfile",
    # rakefile: "Rakefile",
    engine: "script/engine.rb",
    rspec_config: ".rspec",
    server: "script/server.rb"
  }.each do |k, v|
    template("templates/#{k}.erb", "#{app_name}/#{v}")
  end

  inside app_name do
    run "bundle install"
  end

end

#sObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ickgg/command.rb', line 53

def s
  command = "ruby script/server.rb -p #{options[:port] || 3333} -e #{options[:environment] || 'development'}"

  if options[:log]
    command += " -l #{options[:log]}"
  else
    command += " -s"
  end
  if options[:pid]
    command += " -P #{options[:pid]}"
  end
  if options[:daemon]
    command += " -d"
  end

  exec command
end