Sha256: 6d04fa9559ff6cea21986a338f5731293e07844a4e9ed12bf183492596e179c9

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

module Quandl
module Command
class Task

module Configurable
  
  extend ActiveSupport::Concern

  included do
    delegate :auth_token, :quandl_url, to: :config
  end

  module ClassMethods
  end

  def declared_params
    params = {}
    self.class.options.each do |class_type, opts|
      opts.each do |name, desc|
        if options.is_a?(OpenStruct)
          params[name] = self.options.send(name)
        else
          params[name] = self.options[name] if self.options[name].present?
        end
      end
    end
    params
  end
  
  def verbose?
    options.verbose == true
  end
  
  def trace?
    options.trace == true
  end
  
  def confirmed?
    return true if force_yes?
    ask_for_confirmation!
  end
  
  def force_yes?
    options.force_yes == true
  end
  
  def ask_for_confirmation!
    ['y','yes'].include?( ask("Are you sure? (y/n)") )
  end
  
  def page
    @page ||= options.page.to_i || 1
  end
  
  def config
    @config ||= Quandl::Command::Config.new( config_options )
  end
  
  protected
  
  def config_options
    opts = { file_path: config_file_path }
    opts.merge!(options.to_h) if options.to_h.present?
    opts
  end
  
  def config_file_path
    File.join( ENV['HOME'], '.quandl', config_profile )
  end
  
  def config_profile
    options.environment || 'config'
  end

end

end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
quandl-0.3.3 lib/quandl/command/task/configurable.rb
quandl-0.3.0 lib/quandl/command/task/configurable.rb