Class: SalesforceStreamer::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforce_streamer/configuration.rb

Overview

Manages server configuration.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/salesforce_streamer/configuration.rb', line 20

def initialize
  @environment = ENV['RACK_ENV'] || :development
  @logger = Logger.new(IO::NULL)
  @exception_adapter = proc { |exc| fail(exc) }
  @replay_adapter = Hash.new { |hash, key| hash[key] = -1 }
  @manage_topics = false
  @config_file = './config/streamer.yml'
  @require_path = './config/environment'
  @middleware = []
  @faye_extensions = [ReplayIdErrorExtension.new]
end

Class Attribute Details

.instanceObject


15
16
17
# File 'lib/salesforce_streamer/configuration.rb', line 15

def instance
  @instance ||= new
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.


4
5
6
# File 'lib/salesforce_streamer/configuration.rb', line 4

def config_file
  @config_file
end

#environmentObject

Returns the value of attribute environment.


4
5
6
# File 'lib/salesforce_streamer/configuration.rb', line 4

def environment
  @environment
end

#exception_adapterObject

Returns the value of attribute exception_adapter.


4
5
6
# File 'lib/salesforce_streamer/configuration.rb', line 4

def exception_adapter
  @exception_adapter
end

#faye_extensionsObject (readonly)

Returns the value of attribute faye_extensions.


6
7
8
# File 'lib/salesforce_streamer/configuration.rb', line 6

def faye_extensions
  @faye_extensions
end

#loggerObject

Returns the value of attribute logger.


4
5
6
# File 'lib/salesforce_streamer/configuration.rb', line 4

def logger
  @logger
end

#manage_topicsObject

Returns the value of attribute manage_topics.


4
5
6
# File 'lib/salesforce_streamer/configuration.rb', line 4

def manage_topics
  @manage_topics
end

#middlewareObject (readonly)

Returns the value of attribute middleware.


6
7
8
# File 'lib/salesforce_streamer/configuration.rb', line 6

def middleware
  @middleware
end

#replay_adapterObject

Returns the value of attribute replay_adapter.


4
5
6
# File 'lib/salesforce_streamer/configuration.rb', line 4

def replay_adapter
  @replay_adapter
end

#require_pathObject

Returns the value of attribute require_path.


4
5
6
# File 'lib/salesforce_streamer/configuration.rb', line 4

def require_path
  @require_path
end

Class Method Details

.configure {|instance| ... } ⇒ Object

Yields:


11
12
13
# File 'lib/salesforce_streamer/configuration.rb', line 11

def configure
  yield instance
end

Instance Method Details

#manage_topics?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/salesforce_streamer/configuration.rb', line 32

def manage_topics?
  @manage_topics
end

#middleware_runner(last_handler) ⇒ Object

returns a ready to use chain of middleware


47
48
49
50
51
52
# File 'lib/salesforce_streamer/configuration.rb', line 47

def middleware_runner(last_handler)
  @middleware.reduce(last_handler) do |next_handler, current_handler|
    klass, args, block = current_handler
    klass.new(next_handler, *args, &block)
  end
end

#push_topic_dataObject


54
55
56
57
58
59
# File 'lib/salesforce_streamer/configuration.rb', line 54

def push_topic_data
  return @push_topic_data if @push_topic_data

  data = YAML.safe_load(File.read(config_file), aliases: true)
  @push_topic_data = data[environment.to_s]
end

#restforce_logger!Object


61
62
63
# File 'lib/salesforce_streamer/configuration.rb', line 61

def restforce_logger!
  Restforce.log = true
end

#use_faye_extension(extension) ⇒ Object

adds a Faye extension


42
43
44
# File 'lib/salesforce_streamer/configuration.rb', line 42

def use_faye_extension(extension)
  @faye_extensions << extension
end

#use_middleware(klass, *args, &block) ⇒ Object

adds a setup proc to the middleware array


37
38
39
# File 'lib/salesforce_streamer/configuration.rb', line 37

def use_middleware(klass, *args, &block)
  @middleware << [klass, args, block]
end