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, Uninstall, 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.



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

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

Instance Attribute Details

#argsObject

Returns the value of attribute args.



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

def args
  @args
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#request_timerObject

Returns the value of attribute request_timer.



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

def request_timer
  @request_timer
end

Class Method Details

.authenticated_users_only!Object



60
61
62
# File 'lib/quandl/command/tasks/base.rb', line 60

def authenticated_users_only!
  before_execute :authenticated_users_only!
end

.autoload_client_libraryObject



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

def autoload_client_library
  before_execute :configure_client
end

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



72
73
74
75
76
# File 'lib/quandl/command/tasks/base.rb', line 72

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



41
42
43
44
# File 'lib/quandl/command/tasks/base.rb', line 41

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

.configure(app) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/quandl/command/tasks/base.rb', line 18

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



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

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

.disable!Object



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

def disable!
  @disabled = true
end

.disable_in_gem!Object



64
65
66
# File 'lib/quandl/command/tasks/base.rb', line 64

def disable_in_gem!
  before_execute :disable_in_gem!
end

.disabled?Boolean

Returns:

  • (Boolean)


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

def disabled?
  @disabled == true
end

.inherited(klass) ⇒ Object



14
15
16
# File 'lib/quandl/command/tasks/base.rb', line 14

def inherited(klass)
  Tasks.tasks << klass unless Tasks.tasks.include?(klass)
end

.langObject



85
86
87
# File 'lib/quandl/command/tasks/base.rb', line 85

def lang
  @lang ||= Quandl::Lang.send(language).quandl.command.tasks.send(command_name)
end

.languageObject



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

def language
  # stub
  'en'
end

.options(value = nil) ⇒ Object



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

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

.syntax(value = nil) ⇒ Object



36
37
38
39
# File 'lib/quandl/command/tasks/base.rb', line 36

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

.t(key) ⇒ Object



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

def t(key)
  key = key.to_s
  translation = lang
  key.split('.').each{|m| translation = translation.respond_to?(m) ? translation.send(m) : nil }
  translation
end

.warn_unauthenticated_usersObject



68
69
70
# File 'lib/quandl/command/tasks/base.rb', line 68

def warn_unauthenticated_users
  before_execute :warn_unauthenticated_users
end

Instance Method Details

#ask_yes_or_noObject



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

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

#callObject



121
122
123
124
125
# File 'lib/quandl/command/tasks/base.rb', line 121

def call
  run_callbacks(:execute) do
    execute
  end
end

#current_userObject



180
181
182
# File 'lib/quandl/command/tasks/base.rb', line 180

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

#debug(*args) ⇒ Object



164
165
166
# File 'lib/quandl/command/tasks/base.rb', line 164

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

#error(*args) ⇒ Object



168
169
170
# File 'lib/quandl/command/tasks/base.rb', line 168

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

#fatal(*args) ⇒ Object



172
173
174
# File 'lib/quandl/command/tasks/base.rb', line 172

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

#force_yes?Boolean

Returns:

  • (Boolean)


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

def force_yes?
  options.force_yes == true
end

#info(*args) ⇒ Object



160
161
162
# File 'lib/quandl/command/tasks/base.rb', line 160

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

#loggerObject



176
177
178
# File 'lib/quandl/command/tasks/base.rb', line 176

def logger
  Quandl::Logger
end

#summarize(item) ⇒ Object



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

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

#summarize_hash(item) ⇒ Object



149
150
151
152
153
154
# File 'lib/quandl/command/tasks/base.rb', line 149

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



156
157
158
# File 'lib/quandl/command/tasks/base.rb', line 156

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

#verbose?Boolean

Returns:

  • (Boolean)


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

def verbose?
  options.verbose == true
end