diff --git a/bin/console b/bin/console index 8c59b0f..3828443 100755 --- a/bin/console +++ b/bin/console @@ -15,7 +15,9 @@ def rest_client_toggle_log(default=false) end end -pb = Pastebinner::ApiClient.new(ENV['pastebin_api_key'], ENV['pastebin_username'], ENV['pastebin_password']) +# not working yet +config = Pastebinner::Configuration.new +pb = Pastebinner::ApiClient.new(config.api_key, config.api_username, config.api_password) es = Pastebinner::ElasticSearchHelper.new(ENV['elastic_search_url'], 'pastes') # sidekiq worker to send pastes to es diff --git a/config/configuration.rb b/config/configuration.rb index 8b2c72a..18f77cd 100644 --- a/config/configuration.rb +++ b/config/configuration.rb @@ -1,8 +1,13 @@ -# ideally i want to have a configuration block like this loaded -Pastebinner.configure do |config| - config.pastebin_username = pastebin_username - config.pastebin_password = pastebin_password - config.pastebin_api_key = pastebin_api_key - config.elastic_search_url = elastic_search_url - config.redis_url = redis_url +module Pastebinner + class Configuration + attr_accessor :api_key, :api_username, :api_password, :elasticsearch_url, :redis_url + + def initialize + @api_key = nil + @api_username = nil + @api_password = nil + @elasticsearch_url = nil + @redis_url = nil + end + end end diff --git a/lib/pastebinner.rb b/lib/pastebinner.rb index 2b0770c..7da2b72 100755 --- a/lib/pastebinner.rb +++ b/lib/pastebinner.rb @@ -1,4 +1,5 @@ # change this to a config module soon: +require '../config/configuration' require '../config/initializers/sidekiq' require 'rest-client' require 'json' @@ -11,6 +12,21 @@ require 'pastebinner/helpers/elastic_search_helper' require 'pastebinner/workers/paste_to_es' module Pastebinner - class Error < StandardError; end - # your code goes here + + class << self + attr_accessor :configuration + end + + def self.configuration + @configuration ||= Configuration.new + end + + def self.reset + @configuration = Configuration.new + end + + def self.configure + yield(configuration) + end + end