Module: Broker

Defined in:
lib/broker/web_routes.rb,
lib/broker.rb,
lib/broker/cli.rb,
lib/broker/web.rb,
lib/broker/queue.rb,
lib/broker/export.rb,
lib/broker/finder.rb,
lib/broker/import.rb,
lib/broker/payload.rb,
lib/broker/session.rb,
lib/broker/utility.rb,
lib/broker/version.rb,
lib/broker/launcher.rb,
lib/broker/application.rb,
lib/broker/web_helpers.rb

Overview

require ‘broker/import’ require ‘broker/export’

Defined Under Namespace

Modules: Event, Utility, WebHelpers, WebRoutes Classes: Application, CLI, Export, Finder, Import, Launcher, Payload, Poller, Queue, Session, Web

Constant Summary collapse

NAME =
"Broker"
DEFAULTS =
{
  secrets_path: 'config/secrets.yml',
  tables_path: 'config/quickbase_tables.yml',
  initializer: 'config/initializers/broker.rb',
  poll_interval: 300,
  queue: 'broker_queue',
  processed_path: 'broker_processed',
  failed_path: 'broker_failed',
  file_ext: :csv,
  enqueued: []
}
VERSION =
"0.1.2"
@@secrets =
@@secrets ||= load_config(DEFAULTS[:secrets_path])
@@tables =
@@tables  ||= load_config(DEFAULTS[:tables_path])

Class Method Summary collapse

Class Method Details

.any_appObject



68
69
70
# File 'lib/broker.rb', line 68

def self.any_app
  table_keys.first
end

.config_filesObject



51
52
53
54
# File 'lib/broker.rb', line 51

def self.config_files
  fs = [:secrets_path, :tables_path, :initializer]
  options.select { |opt| fs.include? opt }.values
end

.failed_path=(pa) ⇒ Object



100
101
102
# File 'lib/broker.rb', line 100

def self.failed_path=(pa)
  options[:failed_path] = pa
end

.file_ext=(val) ⇒ Object



108
109
110
# File 'lib/broker.rb', line 108

def self.file_ext=(val)
  options[:file_ext] = val if [:csv, :txt].include? val
end

.initializer=(val) ⇒ Object

Initializer setter methods Loaded at runtime in initializers/broker.rb Broker.setup do |config|

config.secrets_path = /my/updated/path.yml

end



78
79
80
# File 'lib/broker.rb', line 78

def self.initializer=(val)
  options[:initializer] = val
end

.launched?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/broker.rb', line 47

def self.launched?
  defined?(Broker::Launcher)
end

.load_config(dest) ⇒ Object



20
21
22
# File 'lib/broker.rb', line 20

def self.load_config(dest)
  YAML.load_file(dest) rescue {}
end

.lookup_appname(key) ⇒ Object



35
36
37
# File 'lib/broker.rb', line 35

def self.lookup_appname(key)
  tables[key.to_s]['name']
end

.lookup_tbid(opt = {}) ⇒ Object



31
32
33
# File 'lib/broker.rb', line 31

def self.lookup_tbid(opt={})
  tables[opt[:app]]['tables'][opt[:table]]
end

.optionsObject



27
28
29
# File 'lib/broker.rb', line 27

def self.options
  @options ||= DEFAULTS.dup
end

.pathObject



39
40
41
# File 'lib/broker.rb', line 39

def self.path
  Dir.pwd
end

.poll_interval=(val) ⇒ Object



104
105
106
# File 'lib/broker.rb', line 104

def self.poll_interval=(val)
  options[:poll_interval] = val
end

.processed_path=(pa) ⇒ Object



96
97
98
# File 'lib/broker.rb', line 96

def self.processed_path=(pa)
  options[:processed_path] = pa
end

.queue=(val) ⇒ Object



92
93
94
# File 'lib/broker.rb', line 92

def self.queue=(val)
  options[:queue] = val
end

.secretsObject



56
57
58
# File 'lib/broker.rb', line 56

def self.secrets
  @@secrets
end

.secrets_path=(pa) ⇒ Object



82
83
84
85
# File 'lib/broker.rb', line 82

def self.secrets_path=(pa)
  options[:secrets_path] = pa
  @@secrets = load_config(pa)
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Broker)

    the object that the method was called on



43
44
45
# File 'lib/broker.rb', line 43

def self.setup
  yield self unless launched?
end

.table_keysObject



64
65
66
# File 'lib/broker.rb', line 64

def self.table_keys
  tables.keys
end

.tablesObject



60
61
62
# File 'lib/broker.rb', line 60

def self.tables
  @@tables
end

.tables_path=(pa) ⇒ Object



87
88
89
90
# File 'lib/broker.rb', line 87

def self.tables_path=(pa)
  options[:tables_path] = pa
  @@tables = load_config(pa)
end