Upgrade to Pro — share decks privately, control downloads, hide ads and more …

fat-settings-yml

TAKAHASHI Kazunari
August 24, 2016
780

 fat-settings-yml

TAKAHASHI Kazunari

August 24, 2016
Tweet

Transcript

  1. DPOpHTFUUJOHTZNM 1 development: 2 smtp: 3 host: smtp.gmail.com 4 username:

    development_user 5 password: password 6 test: 7 smtp: 8 host: smtp.gmail.com 9 username: test_user 10 password: password 11 production: 12 smtp: 13 host: smtp.gmail.com 14 username: production_user 15 password: <%= ENV['SMTP_PASSWORD'] %>
  2. BQQNPEFMTTFUUJOHTSC 1 class Settings < Settingslogic 2 source Rails.root.join('config/settings.yml') 3

    namespace Rails.env 4 suppress_errors Rails.env.production? 5 end 6 7 #=> Settings.smtp.username 8 #=> development_user
  3. 1 development: 2 aws: 3 access_key_id: DEVELOPMENT_ACCESS_KEY_ID 4 secret_access_key: DEVELOPMENT_SECRET_ACCESS_KEY

    5 google: 6 client_id: DEVELOPMENT_GOOGLE_CLIENT_ID.apps.googleusercontent.com 7 secret_key: DEVELOPMENT_SECRET_KEY 8 token_filename: google_drive.json 9 callback_url: http://localhost:3000/oauth/callback 10 foobar_ftp: 11 host: ftp.example.com 12 user: ftp_user 13 password: Ohyee7ak2She 14 export_dirs: 15 shipments: <%= Rails.root.join('tmp', 'shipments') %> 16 products: <%= Rails.root.join('tmp', 'products') %> 17 suppliers: <%= Rails.root.join('tmp', 'suppliers') %> 18 stocks: <%= Rails.root.join('tmp', 'stocks') %> 19 airbrake: 20 project_id: DEVELPMENT_PROJECT_ID 21 project_key: DEVELOPMENT_PROJECT_KEY 22 test: 23 aws: 24 access_key_id: TEST_ACCESS_KEY_ID 25 secret_access_key: TEST_SECRET_ACCESS_KEY 26 google: 27 client_id: TEST_GOOGLE_CLIENT_ID.apps.googleusercontent.com 28 secret_key: TEST_SECRET_KEY 29 token_filename: google_drive.json 30 callback_url: http://localhost:3000/oauth/callback 31 foobar_ftp: 32 host: ftp.example.com 33 user: ftp_user 34 password: Ohyee7ak2She 35 export_dirs: 36 shipments: <%= Rails.root.join('tmp', 'shipments') %> 37 products: <%= Rails.root.join('tmp', 'products') %> 1 production: 2 aws: 3 access_key_id: PRODUCTION_ACCESS_KEY_ID 4 secret_access_key: PRODUCTION_SECRET_ACCESS_KEY 5 google: 6 client_id: PRODUCTION_GOOGLE_CLIENT_ID.apps.googleusercontent.com 7 secret_key: PRODUCTION_SECRET_KEY 8 token_filename: google_drive.json 9 callback_url: http://localhost:3000/oauth/callback 10 foobar_ftp: 11 host: ftp.example.com 12 user: ftp_user 13 password: Ohyee7ak2She --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------
  4. NFUIPE֎Ͱݺͼग़͠ 1 class AdministratorsController < ApplicationController 2 USER = Settings.basic_auth.username

    #=> username͸ະఆٛ 3 PASSWORD = Settings.basic_auth.password 4 5 def index 6 end 7 end
  5. BQQαʔόʔىಈ࣌ʹΤϥʔ $ RAILS_ENV=production bundle exec rails s => Booting Puma

    => Rails 5.0.0.1 application starting in production on http://0.0.0.0:3000 => Run `rails server -h` for more startup options Exiting /usr/local/lib/ruby/gems/2.3.0/gems/ settingslogic-2.0.9/lib/settingslogic.rb:189:in `missing_key': Missing setting 'username' in 'basic_auth' section in /path/to/app/config/ settings.yml (Settingslogic::MissingSetting)
  6. NFUIPE಺Ͱݺͼग़͠ 1 class AdministratorsController < ApplicationController 2 def index 3

    user = Settings.basic_auth.username #=> username͸ະఆٛ 4 password = Settings.basic_auth.password 5 end 6 end
  7. TFUUJOHTZNM 1 development: 2 aws: 3 access_key_id: DEVELOPMENT_ACCESS_KEY_ID 4 secret_access_key:

    DEVELOPMENT_SECRET_ACCESS_KEY 5 google: 6 client_id: DEVELOPMENT_GOOGLE_CLIENT_ID.apps.googleusercontent.com 7 secret_key: DEVELOPMENT_SECRET_KEY 8 token_filename: google_drive.json 9 callback_url: http://localhost:3000/oauth/callback 10 foobar_ftp: 11 host: ftp.example.com 12 user: ftp_user 13 password: Ohyee7ak2She 14 export_dirs: 15 shipments: <%= Rails.root.join('tmp', 'shipments') %> 16 products: <%= Rails.root.join('tmp', 'products') %> 17 suppliers: <%= Rails.root.join('tmp', 'suppliers') %> 18 stocks: <%= Rails.root.join('tmp', 'stocks') %> 19 airbrake: 20 project_id: DEVELPMENT_PROJECT_ID 21 project_key: DEVELOPMENT_PROJECT_KEY
  8. DPOpHTFUUJOHT ZNM $ tree config/settings config/settings ├── airbrake.yml ├── aws.yml

    ├── basic_auth.yml ├── export_dirs.yml ├── foobar_ftp.yml └── smtp.yml
  9. DPOpHTFUUJOHTTNUQZNM 1 development: 2 host: smtp.gmail.com 3 username: development_user 4

    password: password 5 test: 6 host: smtp.gmail.com 7 username: test_user 8 password: password 9 staging: 10 host: smtp.gmail.com 11 username: staging_user 12 password: <%= ENV['SMTP_PASSWORD'] %> 13 production: 14 host: smtp.gmail.com 15 username: production_user 16 password: <%= ENV['SMTP_PASSWORD'] %>
  10. BQQNPEFMTTFUUJOHTTNUQSC 1 class Settings::Smtp < Settingslogic 2 source Rails.root.join('config/settings/smtp.yml') 3

    namespace Rails.env 4 end 5 6 #=> Settings::Smtp.username 7 #=> development_user
  11. DPOpHTFUUJOHTTNUQZNM 1 development: 2 host: smtp.gmail.com 3 username: development_user 4

    password: password 5 test: 6 host: smtp.gmail.com 7 username: test_user 8 password: password 9 staging: 10 host: smtp.gmail.com 11 username: staging_user 12 password: <%= ENV['SMTP_PASSWORD'] %> 13 production: 14 host: smtp.gmail.com 15 username: production_user 16 password: <%= ENV['SMTP_PASSWORD'] %>
  12. 1 namespace :settings do 2 task check: :environment do 3

    Dir.glob(Rails.root.join('app', 'models', 'settings', '*.rb')) { |f| require f } 4 Settingslogic.subclasses.all? do |klass| 5 klass.keys.all? { |m| klass.send(m).present? } 6 end 7 end 8 end
  13. 1 class RailsEnvDetector 2 def self.detect(env = Rails.env) 3 case

    env 4 when /\Astaging/ 5 'staging' 6 else 7 env 8 end 9 end 10 end
  14. BQQNPEFMTTFUUJOHTTNUQSC 1 class Settings::Smtp < Settingslogic 2 source Rails.root.join('config/settings/smtp.yml') 3

    namespace RailsEnvDetector.detect 4 end 5 6 #=> Settings::Smtp.username 7 #=> development_user