Class: Pakyow::Task::Loader
- Inherits:
-
Object
- Object
- Pakyow::Task::Loader
- Defined in:
- lib/pakyow/task.rb
Instance Attribute Summary collapse
-
#__arguments ⇒ Object
readonly
Returns the value of attribute __arguments.
-
#__description ⇒ Object
readonly
Returns the value of attribute __description.
-
#__flags ⇒ Object
readonly
Returns the value of attribute __flags.
-
#__global ⇒ Object
readonly
Returns the value of attribute __global.
-
#__namespace ⇒ Object
readonly
Returns the value of attribute __namespace.
-
#__options ⇒ Object
readonly
Returns the value of attribute __options.
-
#__tasks ⇒ Object
readonly
Returns the value of attribute __tasks.
Instance Method Summary collapse
- #argument(name, description, required: false) ⇒ Object
- #describe(description) ⇒ Object (also: #desc)
- #flag(name, description, short: nil) ⇒ Object
- #global_task(*args, &block) ⇒ Object
-
#initialize(path) ⇒ Loader
constructor
A new instance of Loader.
- #namespace(name, &block) ⇒ Object
- #option(name, description, required: false, short: :default) ⇒ Object
- #task(*args, &block) ⇒ Object
Constructor Details
#initialize(path) ⇒ Loader
Returns a new instance of Loader.
244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/pakyow/task.rb', line 244 def initialize(path) @__namespace = [] @__description = nil @__arguments = {} @__options = {} @__flags = {} @__tasks = [] @__global = false eval(File.read(path), binding, path) end |
Instance Attribute Details
#__arguments ⇒ Object (readonly)
Returns the value of attribute __arguments.
242 243 244 |
# File 'lib/pakyow/task.rb', line 242 def __arguments @__arguments end |
#__description ⇒ Object (readonly)
Returns the value of attribute __description.
242 243 244 |
# File 'lib/pakyow/task.rb', line 242 def __description @__description end |
#__flags ⇒ Object (readonly)
Returns the value of attribute __flags.
242 243 244 |
# File 'lib/pakyow/task.rb', line 242 def __flags @__flags end |
#__global ⇒ Object (readonly)
Returns the value of attribute __global.
242 243 244 |
# File 'lib/pakyow/task.rb', line 242 def __global @__global end |
#__namespace ⇒ Object (readonly)
Returns the value of attribute __namespace.
242 243 244 |
# File 'lib/pakyow/task.rb', line 242 def __namespace @__namespace end |
#__options ⇒ Object (readonly)
Returns the value of attribute __options.
242 243 244 |
# File 'lib/pakyow/task.rb', line 242 def @__options end |
#__tasks ⇒ Object (readonly)
Returns the value of attribute __tasks.
242 243 244 |
# File 'lib/pakyow/task.rb', line 242 def __tasks @__tasks end |
Instance Method Details
#argument(name, description, required: false) ⇒ Object
267 268 269 270 271 272 |
# File 'lib/pakyow/task.rb', line 267 def argument(name, description, required: false) @__arguments[name.to_sym] = { description: description, required: required } end |
#describe(description) ⇒ Object Also known as: desc
262 263 264 |
# File 'lib/pakyow/task.rb', line 262 def describe(description) @__description = description end |
#flag(name, description, short: nil) ⇒ Object
282 283 284 285 286 287 |
# File 'lib/pakyow/task.rb', line 282 def flag(name, description, short: nil) @__flags[name.to_sym] = { description: description, short: short } end |
#global_task(*args, &block) ⇒ Object
311 312 313 314 |
# File 'lib/pakyow/task.rb', line 311 def global_task(*args, &block) @__global = true task(*args, &block) end |
#namespace(name, &block) ⇒ Object
256 257 258 259 260 |
# File 'lib/pakyow/task.rb', line 256 def namespace(name, &block) @__namespace << name.to_sym instance_exec(&block) @__namespace.pop end |
#option(name, description, required: false, short: :default) ⇒ Object
274 275 276 277 278 279 280 |
# File 'lib/pakyow/task.rb', line 274 def option(name, description, required: false, short: :default) @__options[name.to_sym] = { description: description, required: required, short: short } end |
#task(*args, &block) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/pakyow/task.rb', line 289 def task(*args, &block) @__tasks << Task.new( namespace: @__namespace, description: @__description, arguments: @__arguments, options: CLI::GLOBAL_OPTIONS.select { |key, _| key == :env || args[1].to_a.include?(key) }.reject { |key, _| key == :env && args[0] == :prototype }.merge(@__options), flags: @__flags, task_args: args, global: @__global, &block ) @__description = nil @__arguments = {} @__options = {} @__global = false end |