Class: Strobe::CLI::Action
- Inherits:
-
Object
- Object
- Strobe::CLI::Action
show all
- Includes:
- Resources
- Defined in:
- lib/strobe/cli/action.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(settings, options) ⇒ Action
Returns a new instance of Action.
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/strobe/cli/action.rb', line 21
def initialize(settings, options)
@settings = settings
@options = options
@highline = HighLine.new
@resource = nil
@in_group = false
@restart = false
end
|
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
19
20
21
|
# File 'lib/strobe/cli/action.rb', line 19
def actions
@actions
end
|
#options ⇒ Object
Returns the value of attribute options.
19
20
21
|
# File 'lib/strobe/cli/action.rb', line 19
def options
@options
end
|
#restart ⇒ Object
Returns the value of attribute restart.
19
20
21
|
# File 'lib/strobe/cli/action.rb', line 19
def restart
@restart
end
|
#settings ⇒ Object
Returns the value of attribute settings.
19
20
21
|
# File 'lib/strobe/cli/action.rb', line 19
def settings
@settings
end
|
Class Method Details
.run(action, settings, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/strobe/cli/action.rb', line 5
def self.run(action, settings, options = {})
success = false
klass = action.to_s.classify + 'Action'
klass = CLI::Actions.const_get(klass)
until success == true
action = klass.new(settings, options)
action.steps
success = !action.restart
end
end
|
Instance Method Details
#agree(msg, *args) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/strobe/cli/action.rb', line 41
def agree(msg, *args)
@highline.agree(msg, *args) do |q|
next unless STDIN.tty? q.readline = true
end
end
|
#ask(key, options = {}) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/strobe/cli/action.rb', line 48
def ask(key, options = {})
input key, options do |msg|
resp = @highline.ask msg do |q|
next unless STDIN.tty? q.readline = true
end
end
end
|
#choose ⇒ Object
66
67
68
69
70
|
# File 'lib/strobe/cli/action.rb', line 66
def choose
@highline.choose do ||
yield
end
end
|
#group(options = {}, &blk) ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/strobe/cli/action.rb', line 72
def group(options = {}, &blk)
case
when key = options[:validate]
validation_group(key, &blk)
else
yield if block_given?
end
end
|
#password(key, options = {}) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/strobe/cli/action.rb', line 57
def password(key, options = {})
input key, options do |msg|
@highline.ask msg do |q|
next unless STDIN.tty? q.echo = '*'
end
end
end
|
#resource(resource = nil) ⇒ Object
32
33
34
35
|
# File 'lib/strobe/cli/action.rb', line 32
def resource(resource = nil)
@resource = resource if resource
@resource
end
|
#run(action, opts = {}) ⇒ Object
92
93
94
|
# File 'lib/strobe/cli/action.rb', line 92
def run(action, opts = {})
CLI::Action.run(action, settings, opts)
end
|
#save(opts = {}) ⇒ Object
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/strobe/cli/action.rb', line 81
def save(opts = {})
if resource.save
yield
else
display_errors
if opts[:on_error] == :restart
@restart = true
end
end
end
|
#say(what) ⇒ Object
37
38
39
|
# File 'lib/strobe/cli/action.rb', line 37
def say(what)
puts what
end
|