Class: Devserver::CLI

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

Constant Summary collapse

@@default_settings =

defaults

{}
@@default_settings_source =
{}
@@is_rails_dir =
true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.determine_app_rootString

Pretend that we are checking for rails by checking for config/boot.rb we’ll even do something smart for ourselves by chdir .. if ../config/boot.rb exists. “smart for ourselves” is the operative phrase

Returns:

  • (String)

    the current app root path if we think this is a rails dir, else nil



47
48
49
50
51
52
53
54
55
56
# File 'lib/devserver/cli.rb', line 47

def self.determine_app_root
  if(File.exist?('config/boot.rb'))
    return Dir.pwd
  elsif(File.exist?('../config/boot.rb'))
    Dir.chdir('..')
    return Dir.pwd
  else
    return nil
  end
end

.load_defaults_from_yamlObject

Load defaults from a devserver.yaml file located in config/



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/devserver/cli.rb', line 59

def self.load_defaults_from_yaml
  configfile ="#{@@app_root}/config/devserver.yml"
  if File.exists?(configfile) then
    @@default_settings[:configfile] = configfile
    temp = YAML.load_file(configfile)
    if temp.class == Hash
      temp.each do |key,value|
        @@default_settings[key.to_sym] = value
        @@default_settings_source[key.to_sym] = configfile
      end
    end
  end   
end

.set_defaultsObject

sets defaults for the class



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/devserver/cli.rb', line 28

def self.set_defaults
  if(!(@@app_root = self.determine_app_root))
    @@is_rails_dir = false
    @@app_root = '.'
  end
  @@default_settings[:port] = 3000
  @@default_settings[:environment] = 'development'
  @@default_settings[:log_file] = "#{@@app_root}/log/devserver.log"
  @@default_settings[:pid_file] = "#{@@app_root}/tmp/pids/devserver.pid"
  @@default_settings[:mode] = 'start'
  @@default_settings[:server] = 'thin'
  self.load_defaults_from_yaml
end

Instance Method Details

#aboutObject



121
122
123
124
# File 'lib/devserver/cli.rb', line 121

def about
  rails_warning
  puts "Devserver Version #{VERSION}: Provides a wrapper around passenger, thin or mongrel for local ruby on rails development."
end

#commandObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/devserver/cli.rb', line 187

def command
  rails_warning
  the_server = Devserver::CommandManager.new(options)
  gem_warning(the_server)
  if(options[:start])
    puts "start command: #{the_server.command('start')}"
  end
  if(options[:stop])
    puts "stop command: #{the_server.command('stop')}"
  end
  if(options[:debug])
    puts "debug command: #{the_server.command('debug')}"
  end
end

#debugObject



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/devserver/cli.rb', line 156

def debug
  rails_error
  the_server = Devserver::CommandManager.new(options)
  gem_error(the_server)
  if(the_server.is_port_open?)
    puts "Another process is running on Port: #{the_server.port}"
    puts "Running stop command: #{the_server.command(stop)}"
    the_server.stop_devserver
  end
  the_server.start_devserver('debug')
end

#defaultsObject



127
128
129
130
# File 'lib/devserver/cli.rb', line 127

def defaults
  rails_warning
  print_defaults
end

#startObject



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/devserver/cli.rb', line 138

def start
  rails_error
  the_server = Devserver::CommandManager.new(options)
  gem_error(the_server)
  if(the_server.is_port_open?)
    puts "Another process is running on Port: #{the_server.port}"
    puts "Running stop command: #{the_server.command('stop')}"
    the_server.stop_devserver
  end
  the_server.start_devserver
end

#stopObject



170
171
172
173
174
175
176
# File 'lib/devserver/cli.rb', line 170

def stop
  rails_error
  gem_error(the_server)
  the_server = Devserver::CommandManager.new(options)
  gem_error(the_server)
  the_server.stop_devserver      
end