Class: Dreamy::Command::Base
- Inherits:
-
Object
- Object
- Dreamy::Command::Base
show all
- Defined in:
- lib/dreamy/commands/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ Base
Returns a new instance of Base.
7
8
9
10
|
# File 'lib/dreamy/commands/base.rb', line 7
def initialize(args)
@args = args
@account = configure_account
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6
7
8
|
# File 'lib/dreamy/commands/base.rb', line 6
def args
@args
end
|
Instance Method Details
#ask ⇒ Object
21
22
23
|
# File 'lib/dreamy/commands/base.rb', line 21
def ask
gets.strip
end
|
#display(msg, newline = true) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/dreamy/commands/base.rb', line 12
def display(msg, newline=true)
if newline
puts(msg)
else
print(msg)
STDOUT.flush
end
end
|
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/dreamy/commands/base.rb', line 29
def (options, default=true)
values = options.is_a?(Array) ? options : [options]
return unless opt_index = args.select { |a| values.include? a }.first
opt_position = args.index(opt_index) + 1
if args.size > opt_position && opt_value = args[opt_position]
if opt_value.include?('--')
opt_value = nil
else
args.delete_at(opt_position)
end
end
opt_value ||= default
args.delete(opt_index)
block_given? ? yield(opt_value) : opt_value
end
|
#home_directory ⇒ Object
45
46
47
|
# File 'lib/dreamy/commands/base.rb', line 45
def home_directory
running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
end
|
#running_on_windows? ⇒ Boolean
49
50
51
|
# File 'lib/dreamy/commands/base.rb', line 49
def running_on_windows?
RUBY_PLATFORM =~ /mswin32/
end
|
#shell(cmd) ⇒ Object
25
26
27
|
# File 'lib/dreamy/commands/base.rb', line 25
def shell(cmd)
`cd '#{Dir.pwd}' && #{cmd}`
end
|