class Datapimp::Configuration

Constants

DefaultSettings

Public Class Methods

method_missing(meth, *args, &block) click to toggle source
# File lib/datapimp/configuration.rb, line 46
def self.method_missing(meth, *args, &block)
  if instance.respond_to?(meth)
    return instance.send meth, *args, &block
  end

  nil
end

Public Instance Methods

amazon_setup?() click to toggle source
# File lib/datapimp/configuration.rb, line 94
def amazon_setup?
  aws_access_key_id.to_s.length > 0 && aws_secret_access_key.to_s.length > 0
end
applied_config() click to toggle source

Applied config is configuration values passed in context usually from the cli, but also in the unit tests

# File lib/datapimp/configuration.rb, line 190
def applied_config
  @applied_config ||= {}
end
apply_all(options={}) click to toggle source
# File lib/datapimp/configuration.rb, line 124
def apply_all(options={})
  current.merge!(options)
end
apply_config(hash={}) click to toggle source
# File lib/datapimp/configuration.rb, line 155
def apply_config(hash={})
  applied_config.merge!(hash)
  current.merge(applied_config)
end
apply_config_from_path(path) click to toggle source
# File lib/datapimp/configuration.rb, line 160
def apply_config_from_path(path)
  path = Pathname(path)
  parsed = JSON.parse(path.read) rescue {}
  applied_config.merge!(parsed)
  nil
end
calculate_config(using_environment = true) click to toggle source
# File lib/datapimp/configuration.rb, line 137
def calculate_config(using_environment = true)
  @current = defaults.merge(home_config.merge(cwd_config.merge(applied_config))).to_mash

  if ENV['DATAPIMP_CONFIG_EXTRA'].to_s.length > 0
    extra_config = Datapimp::Util.load_config_file(ENV['DATAPIMP_CONFIG_EXTRA'])
    @current.merge!(extra_config) if extra_config.is_a?(Hash)
  end

  (defaults.keys + home_config.keys + cwd_config.keys).uniq.each do |key|
    upper = key.to_s.upcase
    if ENV[upper]
      @current[key] = ENV[upper]
    end
  end if using_environment

  @current
end
current(using_environment = true) click to toggle source
# File lib/datapimp/configuration.rb, line 42
def current(using_environment = true)
  @current ||= calculate_config(using_environment)
end
cwd_config() click to toggle source
# File lib/datapimp/configuration.rb, line 194
def cwd_config
  @cwd_config ||= begin
    (cwd_config_path.exist? rescue false) ? JSON.parse(cwd_config_path.read) : {}
  rescue
    {}
  end
end
cwd_config_path() click to toggle source
# File lib/datapimp/configuration.rb, line 224
def cwd_config_path
  @cwd_config_path || Pathname(Datapimp.pwd).join(manifest_filename)
end
cwd_config_path=(value) click to toggle source
# File lib/datapimp/configuration.rb, line 220
def cwd_config_path= value
  @cwd_config_path = Pathname(value)
end
defaults() click to toggle source
# File lib/datapimp/configuration.rb, line 133
def defaults
  DefaultSettings.dup
end
deploy_manifests_path() click to toggle source
# File lib/datapimp/configuration.rb, line 72
def deploy_manifests_path
  Pathname(home_config_path.dirname).join("deploy-manifests").tap do |dir|
    FileUtils.mkdir_p(dir) unless dir.exist?
  end
end
dnsimple_setup?() click to toggle source
# File lib/datapimp/configuration.rb, line 82
def dnsimple_setup?
  dnsimple_api_token.to_s.length > 0 && dnsimple_username.to_s.length > 0
end
dropbox_setup?() click to toggle source
# File lib/datapimp/configuration.rb, line 86
def dropbox_setup?
  dropbox_app_key.to_s.length > 0 && dropbox_app_secret.to_s.length > 0
end
get(setting) click to toggle source
# File lib/datapimp/configuration.rb, line 112
def get(setting)
  setting = setting.to_s.downcase
  primary_config[setting]
end
google_setup?() click to toggle source
# File lib/datapimp/configuration.rb, line 90
def google_setup?
  google_client_secret.to_s.length > 0 && google_client_id.to_s.length > 0
end
home_config() click to toggle source
# File lib/datapimp/configuration.rb, line 202
def home_config
  initialize! unless home_config_path.exist?

  @home_config ||= begin
    (home_config_path.exist? rescue false) ? JSON.parse(home_config_path.read) : {}
  rescue
    {}
  end
end
home_config_path() click to toggle source
# File lib/datapimp/configuration.rb, line 216
def home_config_path
  @home_config_path || Pathname(ENV['HOME']).join(".datapimp", manifest_filename)
end
home_config_path=(value) click to toggle source
# File lib/datapimp/configuration.rb, line 212
def home_config_path= value
  @home_config_path = Pathname(value)
end
initialize!(fresh=false) click to toggle source
# File lib/datapimp/configuration.rb, line 62
def initialize!(fresh=false)
  return if home_config_path.exist? && !fresh

  FileUtils.mkdir_p home_config_path.dirname

  home_config_path.open("w+") do |fh|
    fh.write(DefaultSettings.to_json)
  end
end
manifest_filename() click to toggle source
# File lib/datapimp/configuration.rb, line 78
def manifest_filename
  "datapimp.json"
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/datapimp/configuration.rb, line 54
def method_missing(meth, *args, &block)
  if current.key?(meth.to_s)
    return current.fetch(meth)
  end

  super
end
primary_config() click to toggle source
# File lib/datapimp/configuration.rb, line 108
def primary_config
  cwd_config_path.exist? ? cwd_config : home_config
end
save!() click to toggle source
# File lib/datapimp/configuration.rb, line 167
def save!
  save_home_config
  save_cwd_config
  @current = nil
  true
end
save_cwd_config() click to toggle source
# File lib/datapimp/configuration.rb, line 174
def save_cwd_config
  return nil unless cwd_config_path.exist?

  File.open(cwd_config_path, 'w+') do |fh|
    fh.write JSON.generate(cwd_config.to_hash)
  end
end
save_home_config() click to toggle source
# File lib/datapimp/configuration.rb, line 182
def save_home_config
  File.open(home_config_path, 'w+') do |fh|
    fh.write JSON.generate(home_config.to_hash)
  end
end
set(setting, value, persist = true, options={}) click to toggle source
# File lib/datapimp/configuration.rb, line 117
def set(setting, value, persist = true, options={})
  setting = setting.to_s.downcase
  primary_config[setting] = value
  save! if persist == true
  value
end
show() click to toggle source
# File lib/datapimp/configuration.rb, line 98
def show
  current.each do |p|
    key, value = p

    unless key == 'sites_directory'
      puts "#{key}: #{ value.inspect }"
    end
  end
end
unset(setting, persist = true) click to toggle source
# File lib/datapimp/configuration.rb, line 128
def unset(setting, persist = true)
  primary_config.delete(setting)
  save! if persist == true
end