Class: Pakyow::Task::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/pakyow/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#__argumentsObject (readonly)

Returns the value of attribute __arguments.



242
243
244
# File 'lib/pakyow/task.rb', line 242

def __arguments
  @__arguments
end

#__descriptionObject (readonly)

Returns the value of attribute __description.



242
243
244
# File 'lib/pakyow/task.rb', line 242

def __description
  @__description
end

#__flagsObject (readonly)

Returns the value of attribute __flags.



242
243
244
# File 'lib/pakyow/task.rb', line 242

def __flags
  @__flags
end

#__globalObject (readonly)

Returns the value of attribute __global.



242
243
244
# File 'lib/pakyow/task.rb', line 242

def __global
  @__global
end

#__namespaceObject (readonly)

Returns the value of attribute __namespace.



242
243
244
# File 'lib/pakyow/task.rb', line 242

def __namespace
  @__namespace
end

#__optionsObject (readonly)

Returns the value of attribute __options.



242
243
244
# File 'lib/pakyow/task.rb', line 242

def __options
  @__options
end

#__tasksObject (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