class Billy::Skill

Constants

ATTRIBUTES

Public Class Methods

new(config = {}) click to toggle source
# File lib/billygoat/skill.rb, line 8
def initialize(config = {})
  config.each { |k,v| public_send("#{k}=",v) }
end

Public Instance Methods

default_task() click to toggle source
# File lib/billygoat/skill.rb, line 33
def default_task
  tasks.first
end
documentation(*args) click to toggle source
# File lib/billygoat/skill.rb, line 49
def documentation(*args)
  execute_task(:documentation, self, *args)
end
documentation?() click to toggle source
# File lib/billygoat/skill.rb, line 45
def documentation?
  !!has_a_task?(:documentation)
end
execute_task(name, *args) click to toggle source
# File lib/billygoat/skill.rb, line 53
def execute_task(name, *args)
  m = Module.new
  require internal_location
  m.extend(self.module)
  m.send(name, *args)
end
find_task(name) click to toggle source
# File lib/billygoat/skill.rb, line 41
def find_task(name)
  tasks.detect{ |task| task.name.to_s.downcase == name.to_s.downcase }
end
has_a_task?(name) click to toggle source
# File lib/billygoat/skill.rb, line 37
def has_a_task?(name)
  !!find_task(name)
end
module() click to toggle source
# File lib/billygoat/skill.rb, line 22
def module
  module_from_string(name)
end
tasks() click to toggle source
# File lib/billygoat/skill.rb, line 26
def tasks
  return @tasks if @tasks
  require internal_location if internal_location
  methods = self.module.instance_methods - Object.new.methods
  @tasks = methods.map { |method| Task.new(name: method, skill: self) }
end
to_h() click to toggle source
# File lib/billygoat/skill.rb, line 16
def to_h
  ATTRIBUTES.each_with_object({}) do |attribute, hash|
    hash[attribute] = public_send(attribute)
  end
end
to_s() click to toggle source
# File lib/billygoat/skill.rb, line 12
def to_s
  name
end

Private Instance Methods

module_from_string(str) click to toggle source
# File lib/billygoat/skill.rb, line 62
def module_from_string(str)
  str.split('::').inject(Object) do |mod, module_name|
    mod.const_get(module_name)
  end
end