Class: Etna::Command
- Inherits:
-
Object
- Object
- Etna::Command
- Includes:
- CommandOrExecutor
- Defined in:
- lib/etna/command.rb
Direct Known Subclasses
GenerateCompletionScript, EtnaApp::Administrate::Models::ApplyTemplate, EtnaApp::Administrate::Models::Attributes::CreateFileLinkingCsv, EtnaApp::Administrate::Models::Attributes::LoadTableFromCsv, EtnaApp::Administrate::Models::Attributes::UpdateFromCsv, EtnaApp::Administrate::Models::CopyTemplate, EtnaApp::Administrate::Models::LoadFromRedcap, EtnaApp::Administrate::Project::Create, EtnaApp::Config::Set, EtnaApp::Config::Show, EtnaApp::Console, EtnaApp::CreateTemplate::AttributeActions, EtnaApp::Polyphemus
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #completions ⇒ Object
-
#execute ⇒ Object
To be overridden during inheritance.
- #fill_in_missing_params(args) ⇒ Object
- #find_command(*args, **kwds) ⇒ Object
-
#initialize(parent = nil) ⇒ Command
constructor
A new instance of Command.
-
#setup(config) ⇒ Object
To be overridden during inheritance, to e.g.
Methods included from CommandOrExecutor
#command_name, #completions_for, #desc, #flag_argspec, #flag_as_parameter, included, #parse_flags, #program_name, #usage
Constructor Details
#initialize(parent = nil) ⇒ Command
Returns a new instance of Command.
223 224 225 |
# File 'lib/etna/command.rb', line 223 def initialize(parent = nil) @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
221 222 223 |
# File 'lib/etna/command.rb', line 221 def parent @parent end |
Class Method Details
.parent_scope ⇒ Object
227 228 229 230 231 |
# File 'lib/etna/command.rb', line 227 def self.parent_scope parts = self.name.split('::') parts.pop Kernel.const_get(parts.join('::')) end |
Instance Method Details
#completions ⇒ Object
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/etna/command.rb', line 246 def completions method(:execute).parameters.map do |type, name| name = "..." if name.nil? if type == :req || type == :opt [completions_for(name)] else [] end end.inject([], &:+) end |
#execute ⇒ Object
To be overridden during inheritance.
258 259 260 261 262 263 |
# File 'lib/etna/command.rb', line 258 def execute raise 'Command is not implemented' rescue => e Rollbar.error(e) raise end |
#fill_in_missing_params(args) ⇒ Object
238 239 240 241 242 243 244 |
# File 'lib/etna/command.rb', line 238 def fill_in_missing_params(args) req_params = method(:execute).parameters.select { |type, name| type == :req } args + (req_params[(args.length)..(req_params.length)] || []).map do |type, name| puts "#{name}?" STDIN.gets.chomp end end |
#find_command(*args, **kwds) ⇒ Object
233 234 235 236 |
# File 'lib/etna/command.rb', line 233 def find_command(*args, **kwds) flags, args = parse_flags(*args) [self, args, kwds.update(flags)] end |
#setup(config) ⇒ Object
To be overridden during inheritance, to e.g. connect to a database. Should be called with super by inheriting method.
267 268 269 270 271 272 |
# File 'lib/etna/command.rb', line 267 def setup(config) Etna::Application.find(self.class).configure(config) rescue => e Rollbar.error(e) raise end |