Class: Snaptoken::Commands::BaseCommand
- Inherits:
-
Object
- Object
- Snaptoken::Commands::BaseCommand
show all
- Defined in:
- lib/snaptoken/commands/base_command.rb
Constant Summary
collapse
- ERROR_MSG =
{
config: {
true: "You are not in a leg working directory.",
false: "You are already in a leg working directory."
},
config_name: {
true: "You need to set a name in leg.yml."
},
config_title: {
true: "You need to set a title in leg.yml."
},
steps_folder: {
true: "There is no steps folder.",
false: "There is already a steps folder."
},
steps: {
true: "There are no steps in the steps folder."
},
repo: {
true: "There is no repo folder.",
false: "There is already a repo folder."
},
diff: {
true: "There is no steps.diff file."
},
doc: {
true: "There is no doc folder."
},
doc_out: {
true: "There are no doc output files."
},
ftp: {
true: "There is no ftp.yml file."
}
}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args, config) ⇒ BaseCommand
Returns a new instance of BaseCommand.
2
3
4
5
|
# File 'lib/snaptoken/commands/base_command.rb', line 2
def initialize(args, config)
@args = args
@config = config
end
|
Class Method Details
.inherited(subclass) ⇒ Object
11
12
13
|
# File 'lib/snaptoken/commands/base_command.rb', line 11
def self.inherited(subclass)
Snaptoken::Commands::LIST << subclass
end
|
.name ⇒ Object
7
|
# File 'lib/snaptoken/commands/base_command.rb', line 7
def self.name; raise NotImplementedError; end
|
.summary ⇒ Object
8
|
# File 'lib/snaptoken/commands/base_command.rb', line 8
def self.summary; raise NotImplementedError; end
|
Instance Method Details
#current_or_latest_step ⇒ Object
108
109
110
|
# File 'lib/snaptoken/commands/base_command.rb', line 108
def current_or_latest_step
current_step || latest_step
end
|
#current_step ⇒ Object
98
99
100
101
102
|
# File 'lib/snaptoken/commands/base_command.rb', line 98
def current_step
if @config[:step_path]
Snaptoken::Step.from_folder_name(File.basename(@config[:step_path]))
end
end
|
#latest_step ⇒ Object
104
105
106
|
# File 'lib/snaptoken/commands/base_command.rb', line 104
def latest_step
steps.last
end
|
#needs!(*whats) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/snaptoken/commands/base_command.rb', line 51
def needs!(*whats)
options = whats.pop if whats.last.is_a? Hash
options ||= {}
yes = Array(whats).flatten.map { |w| [w, true] }
no = Array(options[:not]).map { |w| [w, false] }
(yes + no).each do |what, v|
valid = false
case what
when :config
valid = true if @config
when :config_name
valid = true if @config[:name]
when :config_title
valid = true if @config[:title]
when :steps_folder
valid = true if File.exist?(File.join(@config[:path], "steps"))
when :steps
valid = true if steps.length > 0
when :repo
valid = true if File.exist?(File.join(@config[:path], "repo"))
when :diff
valid = true if File.exist?(File.join(@config[:path], "steps.diff"))
when :doc
valid = true if File.exist?(File.join(@config[:path], "doc"))
when :doc_out
valid = true if File.exist?(File.join(@config[:path], "doc/html_out"))
when :ftp
valid = true if File.exist?(File.join(@config[:path], "ftp.yml"))
else
raise NotImplementedError
end
if valid != v
puts "Error: " + ERROR_MSG[what][v.to_s.to_sym]
exit!
end
end
end
|
#run ⇒ Object
9
|
# File 'lib/snaptoken/commands/base_command.rb', line 9
def run; raise NotImplementedError; end
|
#select_step(step, &block) ⇒ Object
116
117
118
119
|
# File 'lib/snaptoken/commands/base_command.rb', line 116
def select_step(step, &block)
puts "Selecting step: #{step.folder_name}"
FileUtils.cd(step_path(step), &block)
end
|
#step_path(step) ⇒ Object
112
113
114
|
# File 'lib/snaptoken/commands/base_command.rb', line 112
def step_path(step)
File.join(@config[:path], "steps", step.folder_name)
end
|
#steps ⇒ Object
92
93
94
95
96
|
# File 'lib/snaptoken/commands/base_command.rb', line 92
def steps
@steps ||= Dir[File.join(@config[:path], "steps/*")].map do |f|
Snaptoken::Step.from_folder_name(File.basename(f)) if File.directory?(f)
end.compact.sort_by(&:number)
end
|