Module: Cogy
- Defined in:
- lib/cogy.rb,
lib/cogy/engine.rb,
lib/cogy/command.rb,
lib/cogy/context.rb,
lib/cogy/version.rb,
lib/cogy/invocation.rb,
app/controllers/cogy/cogy_controller.rb,
lib/generators/cogy/config_generator.rb,
lib/generators/cogy/install_generator.rb,
app/controllers/cogy/application_controller.rb
Defined Under Namespace
Modules: Generators Classes: ApplicationController, CogyController, Command, Context, Engine
Constant Summary collapse
- COG_BUNDLE_VERSION =
The supported Cog bundle config version.
4- VERSION =
"0.1.0"- @@commands =
Holds all the registered Command objects. Not to be messed with.
{}
- @@bundle_name =
The Cog bundle name.
Used by bundle_config.
"cogy"- @@bundle_description =
The Cog bundle description.
Used by bundle_config.
"Cogy-generated commands"- @@bundle_version =
The Cog bundle version. Can be either a string or an object that responds to ‘#call` and returns a string. Used by bundle_config.
Used by bundle_config.
"0.0.1"- @@executable_path =
The path in the Cog Relay where the cogy executable (ie. github.com/skroutz/cogy-bundle/blob/master/commands/cogy) is located.
Used by bundle_config.
"/usr/bin/cogy"- @@command_load_paths =
Paths where the files that define the commands will be searched in the host application.
["cogy"]
Class Method Summary collapse
-
.bundle_config ⇒ Hash
Generates the bundle config.
-
.configure {|self| ... } ⇒ void
Configures Cogy according to the passed block.
-
.helper(name, &blk) ⇒ void
Defines a user helper method that can be used throughout commands.
-
.on(cmd_name, opts = {}, &handler) ⇒ void
Registers a command to Cogy.
Class Method Details
.bundle_config ⇒ Hash
Generates the bundle config
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cogy.rb', line 103 def self.bundle_config version = if bundle_version.respond_to?(:call) bundle_version.call else bundle_version end config = { "cog_bundle_version" => COG_BUNDLE_VERSION, "name" => bundle_name, "description" => bundle_description, "version" => version, } config["commands"] = {} if commands.present? commands.each do |name, cmd| config["commands"][name] = { "executable" => executable_path, "description" => cmd.desc, "rules" => cmd.rules } if !cmd.args.empty? config["commands"][name]["arguments"] = cmd.formatted_args end if !cmd.opts.empty? config["commands"][name]["options"] = cmd.formatted_opts end if cmd.long_desc config["commands"][name]["long_description"] = cmd.long_desc end if cmd.examples config["commands"][name]["examples"] = cmd.examples end end config end |
.configure {|self| ... } ⇒ void
This method returns an undefined value.
Configures Cogy according to the passed block.
155 156 157 |
# File 'lib/cogy.rb', line 155 def self.configure yield self end |
.helper(name, &blk) ⇒ void
User helpers also have access to the default helpers like ‘user`, `env` etc.
This method returns an undefined value.
Defines a user helper method that can be used throughout commands.
176 177 178 |
# File 'lib/cogy.rb', line 176 def self.helper(name, &blk) Context.class_eval { define_method(name, blk) } end |
.on(cmd_name, opts = {}, &handler) ⇒ void
If you want to return early in a point inside a command block, ‘next` should be used instead of `return`, due to the way Proc objects work in Ruby.
This method returns an undefined value.
Registers a command to Cogy. All the options passed are used solely for generating the bundle config (ie. bundle_config). The passed block is the code that will get executed when the command is invoked.
The last value of the block is what will get printed as the result of the command. It should be a string. If you want to return early in a point inside the block, use ‘next` instead of `return`.
Inside the command block, there are the public attributes of Context available.
95 96 97 98 |
# File 'lib/cogy.rb', line 95 def self.on(cmd_name, opts = {}, &handler) cmd = Command.new(cmd_name, handler, opts) cmd.register! end |