Class: Driftwood

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/driftwood.rb,
lib/driftwood/plugin.rb,
lib/driftwood/version.rb

Defined Under Namespace

Classes: Bigquery, Plugin, Slack

Constant Summary collapse

VERSION =
'0.0.8'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil) ⇒ Driftwood

Returns a new instance of Driftwood.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/driftwood.rb', line 20

def initialize(app=nil)
  super(app)
  $logger.info "Starting Driftwood v#{Driftwood::VERSION}"
  @bigquery = Driftwood::Bigquery.new(settings.gcloud)
  @slack    = Driftwood::Slack.new(settings.slack)
  @app_id   = settings.slack[:client_id]
  @slack.authorize(cached_auth)

  @plugins = settings.plugins.map do |plugin, config|
    filename = plugin.snake_case

    begin
      require "driftwood/plugin/#{filename}"
    rescue LoadError
      require filename
    end

    Driftwood::Plugin::const_get(plugin).new(config, @slack, @bigquery)
  end

  # help handler
  @slack.register_handler('message') do |team_id, event_data|
    user = event_data['user']
    text = event_data['text']

    case text
    when /^help$/i
      @slack.send_response(team_id, user, "Usage for all plugins:")
      @plugins.each do |plugin|
        next unless plugin.usage
        @slack.send_response(team_id, user, plugin.usage)
      end
    when /^help (\w*)$/i
      name = $1
      @slack.send_response(team_id, user, "Usage for #{name}:")
      @plugins.each do |plugin|
        next unless plugin.name = name.downcase
        @slack.send_response(team_id, user, plugin.usage)
      end
    end
  end

end

Instance Attribute Details

#bigqueryObject (readonly)

this allows other tools to register handlers and interact with the db



18
19
20
# File 'lib/driftwood.rb', line 18

def bigquery
  @bigquery
end

#slackObject (readonly)

this allows other tools to register handlers and interact with the db



18
19
20
# File 'lib/driftwood.rb', line 18

def slack
  @slack
end