Class: Perkins::Application

Inherits:
Object show all
Defined in:
lib/perkins/application.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Application

Returns a new instance of Application.



11
12
13
14
15
16
17
18
19
20
# File 'lib/perkins/application.rb', line 11

def initialize(opts={})
  @host = opts[:host] unless opts[:host].blank?
  @post = opts[:port] unless opts[:port].blank?
  @github_client_id = opts[:github_client_id] unless opts[:github_client_id].blank?
  @github_client_server = opts[:github_client_secret] unless opts[:github_client_secret].blank?
  working_dir = opts[:working_dir] unless opts[:working_dir].blank?
  self.class.instance = self
  self.init_github_client
  self
end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



8
9
10
# File 'lib/perkins/application.rb', line 8

def instance
  @instance
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



3
4
5
# File 'lib/perkins/application.rb', line 3

def database
  @database
end

#github_client_idObject

Returns the value of attribute github_client_id.



5
6
7
# File 'lib/perkins/application.rb', line 5

def github_client_id
  @github_client_id
end

#github_client_secretObject

Returns the value of attribute github_client_secret.



5
6
7
# File 'lib/perkins/application.rb', line 5

def github_client_secret
  @github_client_secret
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/perkins/application.rb', line 3

def host
  @host
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/perkins/application.rb', line 3

def port
  @port
end

#redisObject

Returns the value of attribute redis.



3
4
5
# File 'lib/perkins/application.rb', line 3

def redis
  @redis
end

#serverObject (readonly)

Returns the value of attribute server.



4
5
6
# File 'lib/perkins/application.rb', line 4

def server
  @server
end

#sse_endpointObject

Returns the value of attribute sse_endpoint.



3
4
5
# File 'lib/perkins/application.rb', line 3

def sse_endpoint
  @sse_endpoint
end

#working_dirObject

Returns the value of attribute working_dir.



3
4
5
# File 'lib/perkins/application.rb', line 3

def working_dir
  @working_dir
end

Instance Method Details

#as_json(options = {}) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/perkins/application.rb', line 51

def as_json(options = {})
  data = {}
  fields = [:host, :port, :github_client_id,
            :github_client_secret, :working_dir]

  fields.each { |k| data[k] = send(k) }
  data
end

#init_github_clientObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/perkins/application.rb', line 32

def init_github_client
  #$github_client = Octokit::Client.new \
  #  :client_id     => @github_client_id,
  #  :client_secret => @github_client_server
  
  #GLOBAL SERVER 2 SERVER GITHUB CLIENT
  $github_client ||= Octokit::Client.new(
    login: ENV['LOGIN'],
    access_token: ENV['ACCESS_TOKEN']
  )

end

#setup_sidekiqObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/perkins/application.rb', line 60

def setup_sidekiq
  # Sidekiq server is multi-threaded so our Redis connection pool size defaults to concurrency (-c)
  Sidekiq.configure_server do |config|
    config.redis = { :namespace => 'perkins-worker' }
    if defined?(ActiveRecord::Base)
      #ActiveRecord::Base.establish_connection
      #Perkins::Application.instance.database
      ActiveRecord::Base.establish_connection(@dbconfig[ENV['RACK_ENV']])
    end
  end

  Sidekiq.configure_client do |config|
    config.redis = { :namespace => 'perkins-worker' }
  end

end