class Hatenablog::Configuration

Constants

BASIC_KEYS
OAUTH_KEYS

@dynamic auth_type, consumer_key, consumer_secret, access_token, access_token_secret, api_key, user_id, blog_id

Public Class Methods

create(config_file) click to toggle source

Create a new configuration. @param [String] config_file configuration file path @return [Hatenablog::Configuration]

# File lib/hatenablog/configuration.rb, line 15
def self.create(config_file)
  loaded_config = YAML.load(ERB.new(File.read(config_file)).result)
  config = new(loaded_config)
  config.check_valid_or_raise
end

Public Instance Methods

check_valid_or_raise() click to toggle source
# File lib/hatenablog/configuration.rb, line 21
def check_valid_or_raise
  unless (lacking_keys = self.send(:lacking_keys)).empty?
    raise ConfigurationError, "Following keys are not setup. #{lacking_keys.map(&:to_s)}"
  end
  self
end

Private Instance Methods

lacking_keys() click to toggle source
# File lib/hatenablog/configuration.rb, line 30
def lacking_keys
  required_keys = self['auth_type'] == 'basic' ? BASIC_KEYS : OAUTH_KEYS
  config_keys   = to_h.keys
  required_keys.select { |key| !config_keys.include?(key) }
end