Module: ExtJS::XTheme::Command

Defined in:
lib/extjs-xtheme/command.rb,
lib/extjs-xtheme/commands/base.rb,
lib/extjs-xtheme/commands/help.rb,
lib/extjs-xtheme/commands/theme.rb,
lib/extjs-xtheme/commands/conifg.rb,
lib/extjs-xtheme/commands/effects.rb

Defined Under Namespace

Classes: Base, CommandFailed, Config, ConfigNotFound, Effects, Help, InvalidCommand, InvalidConfig, Theme

Class Method Summary collapse

Class Method Details

.error(msg) ⇒ Object



51
52
53
54
# File 'lib/extjs-xtheme/command.rb', line 51

def error(msg)
	STDERR.puts(msg)
	exit 1
end

.load_configObject



76
77
78
# File 'lib/extjs-xtheme/command.rb', line 76

def load_config
  File.exists?('.xthemeconfig') ? YAML::load(File.open('.xthemeconfig')) : nil
end

.parse(command) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/extjs-xtheme/command.rb', line 56

def parse(command)
	parts = command.split(':')
	case parts.size
		when 1
			begin
				return eval("ExtJS::XTheme::Command::#{command.capitalize}"), :index
			rescue NameError, NoMethodError
			  return ExtJS::XTheme::Command::Theme, command
			end
		when 2
			begin
				return ExtJS::XTheme::Command.const_get(parts[0].capitalize), parts[1]
			rescue NameError
				raise InvalidCommand
			end
		else
			raise InvalidCommand
	end
end

.run(command, args, retries = 0) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/extjs-xtheme/command.rb', line 13

def run(command, args, retries=0)
	begin
		run_internal(command, args.dup)
	rescue InvalidCommand
		error "Unknown command. Run 'xtheme help' for usage information."
	rescue CommandFailed => e
		error e.message
	rescue InvalidConfig => e
	  error e.message
	rescue ConfigNotFound => e
	  error e.message
	rescue Interrupt => e
		error "\n[canceled]"
	end
end

.run_internal(command, args, heroku = nil) ⇒ Object

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/extjs-xtheme/command.rb', line 29

def run_internal(command, args, heroku=nil)
  config = load_config
  
	klass, method = parse(command)
	
	unless method == "init"
	  unless config 
	    raise ConfigNotFound.new("Could not locate config file .xthemeconfig.\nAre you in your application root?  Have you run xtheme init?")
			end
	  unless config && File.exists?(config[:ext_dir])
			  raise InvalidConfig.new("Could not locate ext_dir #{config[:ext_dir]}.\nAre you in your application root?")
			end
			unless config && File.exists?(config[:theme_dir])
			  raise InvalidConig.new("Could not locate theme_dir #{config[:theme_dir]}.\nAre you in your application root?")
	  end
	end
	
	runner = klass.new(args, config)
	raise InvalidCommand unless runner.respond_to?(method)
	runner.send(method)
end