lib/broker.rb in broker-0.0.9 vs lib/broker.rb in broker-0.1.1
- old
+ new
@@ -1,6 +1,7 @@
require 'broker/version'
+#require 'broker/session'
require 'yaml'
module Broker
NAME = "Broker: Quickbase Data Intake"
@@ -8,27 +9,34 @@
secrets_path: 'config/secrets.yml',
tables_path: 'config/quickbase_tables.yml',
initializer: 'config/initializers/broker.rb',
poll_interval: 300,
queue: 'broker_queue',
- file_ext: :csv
+ processed_path: 'broker_processed',
+ file_ext: :csv,
+ enqueued: []
}
- @@secrets_path = @@secrets_path ||= DEFAULTS[:secrets_path]
- @@tables_path = @@tables_path ||= DEFAULTS[:tables_path]
- @@initializer = @@initializer ||= DEFAULTS[:initializer]
- @@poll_interval = @poll_interval ||= DEFAULTS[:poll_interval]
- @@queue = @@queue ||= DEFAULTS[:queue]
- @@file_ext = @@file_ext ||= DEFAULTS[:file_ext]
+ def self.load_config(dest)
+ YAML.load_file(dest) rescue {}
+ end
- @@secrets = YAML.load_file(@@secrets_path) rescue {}
- @@tables = YAML.load_file(@@tables_path) rescue {}
+ @@secrets = @@secrets ||= load_config(DEFAULTS[:secrets_path])
+ @@tables = @@tables ||= load_config(DEFAULTS[:tables_path])
+ def self.options
+ @options ||= DEFAULTS.dup
+ end
+
def self.lookup_tbid(opt={})
tables[opt[:app]]['tables'][opt[:table]]
end
+ def self.lookup_appname(key)
+ tables[key.to_s]['name']
+ end
+
def self.path
Dir.pwd
end
def self.setup
@@ -38,78 +46,64 @@
def self.launched?
defined?(Broker::Launcher)
end
def self.config_files
- [secrets_path, tables_path, initializer]
+ fs = [:secrets_path, :tables_path, :initializer]
+ options.select { |opt| fs.include? opt }.values
end
- # def self.options
-# @options ||= DEFAULTS.dup
-# end
-#
-# def self.options=(opt)
-# @options = opt
-# end
-
- def self.poll_interval
- @@poll_interval
+ def self.secrets
+ @@secrets
end
- def self.poll_interval=(val)
- @@poll_interval = val
+ def self.tables
+ @@tables
end
- def self.queue
- @@queue
+ def self.table_keys
+ tables.keys
end
- def self.queue=(val)
- @@queue = val
+ def self.any_app
+ table_keys.first
end
- def file_ext
- @@file_ext
- end
+ # Initializer setter methods
+ # Loaded at runtime in initializers/broker.rb
+ # Broker.setup do |config|
+ # config.secrets_path = /my/updated/path.yml
+ # end
- def file_ext=(val)
- @@file_ext = val if [:csv, :tab].include? val
+ def self.initializer=(val)
+ options[:initializer] = val
end
- def self.secrets
- @@secrets
+ def self.secrets_path=(pa)
+ options[:secrets_path] = pa
+ @@secrets = load_config(pa)
end
- def self.secrets_path
- @@secrets_path
+ def self.tables_path=(pa)
+ options[:tables_path] = pa
+ @@tables = load_config(pa)
end
- def self.secrets_path=(val)
- @@secrets_path = val
- @@secrets = YAML.load_file(@@secrets_path) rescue {}
+ def self.queue=(val)
+ options[:queue] = val
end
- def self.tables
- @@tables
+ def self.processed_path=(pa)
+ options[:processed_path] = pa
end
- def self.tables_path
- @@tables_path
+ def self.poll_interval=(val)
+ options[:poll_interval] = val
end
- def self.tables_path=(val)
- @@tables_path = val
- @@tables = YAML.load_file(@@tables_path) rescue {}
+ def file_ext=(val)
+ options[:file_ext] = val if [:csv, :tab].include? val
end
- def self.initializer
- @@initializer
- end
-
- def self.initializer=(val)
- @@initializer = val
- end
-
end
require 'broker/application'
-