Sha256: 4687a20959cc54efd84925e88b9b341ce0fd065fb611eaa08c63e383d9c4e9e0

Contents?: true

Size: 652 Bytes

Versions: 1

Compression:

Stored size: 652 Bytes

Contents

module AnythingHub
  extend self

  def command_set(&block)
    class_eval(&block)
  end

  def command(name, &block)
    if block
      commands << {:pattern => /^#{name}(:.+)?/, :block => block}
    else
      cmd = commands.detect { |c| c[:pattern] =~ name }
      cmd[:block].call(name)
    end
  end

  def commands
    @commands ||= []
  end

  def fetch_from_api_or_cache(cache_key, &api)
    unless options[:cache] == "no"
      cache_data = JSON.parse(cache.read(cache_key)) rescue nil
    end
    if cache_data
      cache_data
    else
      response = api.call
      cache.write cache_key, response.to_json
      response
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
anything-hub-0.0.1 lib/anything-hub/command_set.rb