# HG changeset patch # User nanaya # Date 1429772708 -32400 # Node ID e5082c4c234dea3b3f3ea52b16957a986311faba # Parent 92b22027d0ae33ae0dfba9f64fd49e2c75d5d052 Also allow config-file-based configuration. diff -r 92b22027d0ae -r e5082c4c234d app/models/tweet.rb --- a/app/models/tweet.rb Thu Apr 23 15:32:56 2015 +0900 +++ b/app/models/tweet.rb Thu Apr 23 16:05:08 2015 +0900 @@ -1,11 +1,4 @@ class Tweet - CONFIG = { - :consumer_key => ENV["RT_CONSUMER_KEY"], - :consumer_secret => ENV["RT_CONSUMER_SECRET"], - :access_token => ENV["RT_ACCESS_TOKEN"], - :access_token_secret => ENV["RT_ACCESS_TOKEN_SECRET"] - } - def timeline @timeline ||= Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => 5.minutes) do @@ -15,7 +8,7 @@ def initialize(twitter_id) @client = Twitter::REST::Client.new do |config| - CONFIG.each do |cfg_key, cfg_value| + CFG[:twitter].each do |cfg_key, cfg_value| config.public_send("#{cfg_key}=", cfg_value) end end diff -r 92b22027d0ae -r e5082c4c234d config/application.rb --- a/config/application.rb Thu Apr 23 15:32:56 2015 +0900 +++ b/config/application.rb Thu Apr 23 16:05:08 2015 +0900 @@ -9,6 +9,8 @@ # require "sprockets/railtie" require "rails/test_unit/railtie" +require File.expand_path("../config_init", __FILE__) + # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) @@ -32,8 +34,8 @@ config.secret_key_base = "herp a derp" config.session_store :disabled - if ENV["RT_MEMCACHED_SERVERS"] - config.cache_store = :mem_cache_store, ENV["RT_MEMCACHED_SERVERS"].split(","), { :namespace => "rsstweet" } + if CFG[:memcached_servers] + config.cache_store = :mem_cache_store, CFG[:memcached_servers], { :namespace => "rsstweet" } end end end diff -r 92b22027d0ae -r e5082c4c234d config/config_init.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/config_init.rb Thu Apr 23 16:05:08 2015 +0900 @@ -0,0 +1,13 @@ +CFG = { + :twitter => { + :consumer_key => ENV["RT_CONSUMER_KEY"], + :consumer_secret => ENV["RT_CONSUMER_SECRET"], + :access_token => ENV["RT_ACCESS_TOKEN"], + :access_token_secret => ENV["RT_ACCESS_TOKEN_SECRET"] + }, + :memcached_servers => ENV["RT_MEMCACHED_SERVERS"].try(:split, ",") +} + +config_local = File.expand_path("../config_local_#{Rails.env}.rb", __FILE__) + +require config_local if File.exist? config_local