Class: Quandl::Command::Tasks::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Includes:
ActiveModel::Validations
Defined in:
lib/quandl/command/tasks/base.rb

Direct Known Subclasses

Delete, Download, Info, List, Login, Update, Upload

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, options) ⇒ Base

Returns a new instance of Base.



95
96
97
98
# File 'lib/quandl/command/tasks/base.rb', line 95

def initialize(args, options)
  self.args = args
  self.options = options
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



79
80
81
# File 'lib/quandl/command/tasks/base.rb', line 79

def args
  @args
end

#optionsObject

Returns the value of attribute options.



79
80
81
# File 'lib/quandl/command/tasks/base.rb', line 79

def options
  @options
end

#request_timerObject

Returns the value of attribute request_timer.



79
80
81
# File 'lib/quandl/command/tasks/base.rb', line 79

def request_timer
  @request_timer
end

Class Method Details

.authenticated_users_only!Object



48
49
50
# File 'lib/quandl/command/tasks/base.rb', line 48

def authenticated_users_only!
  before_execute :authenticated_users_only!
end

.call(args = [], options = {}) ⇒ Object



56
57
58
59
60
# File 'lib/quandl/command/tasks/base.rb', line 56

def call(args=[], options={})
  args = Array(args)
  options = ensure_options_are_command_options!(options)
  self.new( args, options ).call
end

.command_name(value = nil) ⇒ Object



33
34
35
36
# File 'lib/quandl/command/tasks/base.rb', line 33

def command_name(value=nil)
  @command_name = value if value.present?
  @command_name ||= name.to_s.split("::").last.downcase
end

.configure(app) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/quandl/command/tasks/base.rb', line 10

def configure(app)
  return if disabled?
  app.command(command_name) do |c|
    c.syntax = syntax
    c.description = description
    c.action{|a,o| call(a,o) }
    configure_options(c)
  end
end

.description(value = nil) ⇒ Object



38
39
40
41
# File 'lib/quandl/command/tasks/base.rb', line 38

def description(value=nil)
  @description = value if value.present?
  @description ||= "No description."
end

.disable!Object



24
25
26
# File 'lib/quandl/command/tasks/base.rb', line 24

def disable!
  @disabled = true
end

.disabled?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/quandl/command/tasks/base.rb', line 20

def disabled?
  @disabled == true
end

.options(value = nil) ⇒ Object



43
44
45
46
# File 'lib/quandl/command/tasks/base.rb', line 43

def options(value=nil)
  @options = value if value.present?
  @options ||= {}
end

.syntax(value = nil) ⇒ Object



28
29
30
31
# File 'lib/quandl/command/tasks/base.rb', line 28

def syntax(value=nil)
  @syntax = value if value.present?
  @syntax ||= "quandl #{command_name}"
end

.warn_unauthenticated_usersObject



52
53
54
# File 'lib/quandl/command/tasks/base.rb', line 52

def warn_unauthenticated_users
  before_execute :warn_unauthenticated_users
end

Instance Method Details

#ask_yes_or_noObject



108
109
110
# File 'lib/quandl/command/tasks/base.rb', line 108

def ask_yes_or_no
  ['y','yes'].include?( ask("Are you sure? (y/n)") )
end

#callObject



89
90
91
92
93
# File 'lib/quandl/command/tasks/base.rb', line 89

def call
  run_callbacks(:execute) do
    execute
  end
end

#current_userObject



148
149
150
# File 'lib/quandl/command/tasks/base.rb', line 148

def current_user
  @current_user ||= Quandl::Client::User.info
end

#debug(*args) ⇒ Object



132
133
134
# File 'lib/quandl/command/tasks/base.rb', line 132

def debug(*args)
  logger.debug(*args) if verbose?
end

#error(*args) ⇒ Object



136
137
138
# File 'lib/quandl/command/tasks/base.rb', line 136

def error(*args)
  logger.error(*args)
end

#fatal(*args) ⇒ Object



140
141
142
# File 'lib/quandl/command/tasks/base.rb', line 140

def fatal(*args)
  logger.fatal("FATAL: #{args.join(" ")}")
end

#force_yes?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/quandl/command/tasks/base.rb', line 104

def force_yes?
  options.force_yes == true
end

#info(*args) ⇒ Object



128
129
130
# File 'lib/quandl/command/tasks/base.rb', line 128

def info(*args)
  logger.info(*args)
end

#loggerObject



144
145
146
# File 'lib/quandl/command/tasks/base.rb', line 144

def logger
  Quandl::Logger
end

#summarize(item) ⇒ Object



112
113
114
115
# File 'lib/quandl/command/tasks/base.rb', line 112

def summarize(item)
  return summarize_hash(item) if item.kind_of?(Hash)
  item
end

#summarize_hash(item) ⇒ Object



117
118
119
120
121
122
# File 'lib/quandl/command/tasks/base.rb', line 117

def summarize_hash(item)
  item.collect do |k,v|
    next "#{k}: '#{v}'" if v.kind_of?(String)
    "#{k}: #{v}"
  end.join(', ')
end

#table(*args) ⇒ Object



124
125
126
# File 'lib/quandl/command/tasks/base.rb', line 124

def table(*args)
  Array(args).flatten.join(" | ")
end

#verbose?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/quandl/command/tasks/base.rb', line 100

def verbose?
  options.verbose == true
end