class Memot::Config

Public Class Methods

load_env() click to toggle source
# File lib/memot/config.rb, line 12
def load_env
  auth = {
    dropbox: {
      app_key: ENV["MEMOT_DROPBOX_APP_KEY"],
      app_secret: ENV["MEMOT_DROPBOX_APP_SECRET"],
      access_token: ENV["MEMOT_DROPBOX_ACCESS_TOKEN"],
    },
    evernote: {
      token: ENV["MEMOT_EVERNOTE_TOKEN"],
      sandbox: ENV["MEMOT_EVERNOTE_SANDBOX"].downcase == "true",
    },
  }

  if ENV["MEMOT_NOTES"]
    #
    # daily:/memo/daily,reading:/memo/reading
    #   -> { daily: "/memo/daily", reading: "/memo/reading" }
    #
    notes = ENV["MEMOT_NOTES"].split(",").map { |pair| pair.split(":") }.inject({}) do |nts, kv|
      nts[kv[0]] = kv[1]
      nts
    end
  else
    notes = {}
  end

  self.new(auth, notes)
end
load_yaml(yaml_path) click to toggle source
# File lib/memot/config.rb, line 4
def load_yaml(yaml_path)
  yaml = symbolize_keys(YAML.load_file(yaml_path))
  auth = yaml[:auth] || {}
  notes = yaml[:notes] || {}

  self.new(auth, notes)
end
new(auth, notes) click to toggle source
# File lib/memot/config.rb, line 60
def initialize(auth, notes)
  @auth = auth
  @notes = notes
end

Private Class Methods

symbolize_keys(hash) click to toggle source
# File lib/memot/config.rb, line 43
def symbolize_keys(hash)
  result = {}

  hash.each_pair do |key, value|
    result[key.to_sym] = if value.is_a? Array
                           value.each { |element| symbolize_keys(element) }
                         elsif value.is_a? Hash
                           symbolize_keys(value)
                         else
                           value
                         end
  end

  result
end

Public Instance Methods

auth() click to toggle source
# File lib/memot/config.rb, line 65
def auth
  @auth
end
notes() click to toggle source
# File lib/memot/config.rb, line 69
def notes
  @notes
end