Class: JaxGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/jax/generators/commands.rb

Constant Summary collapse

COMMANDS =
{
  "generate" => "Generate new code",
  "destroy"  => "Undo code generated with \"generate\"",
  "plugin"   => "Install a plugin",
  "package"  => "Package the app for production"
}
ALIASES =
{ "g" => "generate" }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ JaxGenerator

Returns a new instance of JaxGenerator.



150
151
152
153
154
155
156
157
158
159
# File 'lib/jax/generators/commands.rb', line 150

def initialize(args)
  @args = args
  
  show_usage and return unless command
  if respond_to? command then send command
  else invalid command
  end
rescue ArgumentError
  puts $!.message
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



140
141
142
# File 'lib/jax/generators/commands.rb', line 140

def args
  @args
end

Class Method Details

.startObject

this gets called by script/jax from within a jax app



215
216
217
# File 'lib/jax/generators/commands.rb', line 215

def start
  new ARGV
end

Instance Method Details

#commandObject



177
178
179
180
181
182
# File 'lib/jax/generators/commands.rb', line 177

def command
  @command ||= begin
    command = args.shift
    command = ALIASES[command] || command
  end
end

#command_listObject



201
202
203
# File 'lib/jax/generators/commands.rb', line 201

def command_list
  COMMANDS.keys.collect { |command| "#{command.ljust(13)}#{description_for command}"}
end

#description_for(command) ⇒ Object



205
206
207
208
209
210
211
# File 'lib/jax/generators/commands.rb', line 205

def description_for(command)
  if i = ALIASES.values.index(command)
    COMMANDS[command] + " (shortcut alias: \"#{ALIASES.keys[i]}\")"
  else
    COMMANDS[command]
  end
end

#destroyObject



169
170
171
# File 'lib/jax/generators/commands.rb', line 169

def destroy
  JaxGeneratorInvoker.start(ARGV, :behavior => :revoke)
end

#generateObject



165
166
167
# File 'lib/jax/generators/commands.rb', line 165

def generate
  JaxGeneratorInvoker.start
end

#invalid(command) ⇒ Object



184
185
186
187
188
# File 'lib/jax/generators/commands.rb', line 184

def invalid(command)
  puts "Invalid command."
  puts
  show_usage
end

#packageObject



161
162
163
# File 'lib/jax/generators/commands.rb', line 161

def package
  Jax::Generators::Packager::PackageGenerator.start
end

#pluginObject



173
174
175
# File 'lib/jax/generators/commands.rb', line 173

def plugin
  Jax::Generators::Plugin::PluginManager.start
end

#show_usageObject



190
191
192
193
194
195
196
197
198
199
# File 'lib/jax/generators/commands.rb', line 190

def show_usage
  puts <<-end_banner
Usage: jax COMMAND [ARGS]

The following commands are available:
#{command_list.join("\n  ")}

All commands can be run with -h for more information.
  end_banner
end