Class: Etna::Command
- Inherits:
-
Object
- Object
- Etna::Command
- Includes:
- CommandOrExecutor
- Defined in:
- lib/etna/command.rb
Direct Known Subclasses
GenerateCompletionScript, EtnaApp::Config::Set, EtnaApp::Config::Show, EtnaApp::Console, EtnaApp::CreateTemplate::AttributeActions, EtnaApp::Janus::Token::Generate, EtnaApp::Magma::Materialize, EtnaApp::Magma::Models::ApplyTemplate, EtnaApp::Magma::Models::Attributes::CreateFileLinkingCsv, EtnaApp::Magma::Models::Attributes::LoadTableFromCsv, EtnaApp::Magma::Models::Attributes::UpdateFromCsv, EtnaApp::Magma::Models::CopyTemplate, EtnaApp::Magma::Models::LoadFromRedcap, EtnaApp::Magma::Models::SetDateShiftRoot, EtnaApp::Magma::Project::Create, EtnaApp::Metis::PullArchive, EtnaApp::Metis::PutArchive, 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.
224 225 226 |
# File 'lib/etna/command.rb', line 224 def initialize(parent = nil) @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
222 223 224 |
# File 'lib/etna/command.rb', line 222 def parent @parent end |
Class Method Details
.parent_scope ⇒ Object
228 229 230 231 232 |
# File 'lib/etna/command.rb', line 228 def self.parent_scope parts = self.name.split('::') parts.pop Kernel.const_get(parts.join('::')) end |
Instance Method Details
#completions ⇒ Object
247 248 249 250 251 252 253 254 255 256 |
# File 'lib/etna/command.rb', line 247 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.
259 260 261 262 263 264 |
# File 'lib/etna/command.rb', line 259 def execute raise 'Command is not implemented' rescue => e Rollbar.error(e) raise end |
#fill_in_missing_params(args) ⇒ Object
239 240 241 242 243 244 245 |
# File 'lib/etna/command.rb', line 239 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
234 235 236 237 |
# File 'lib/etna/command.rb', line 234 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.
268 269 270 271 272 273 |
# File 'lib/etna/command.rb', line 268 def setup(config) Etna::Application.find(self.class).configure(config) rescue => e Rollbar.error(e) raise end |