Class: Hyraft::Rule::SourceCommand
- Inherits:
-
Object
- Object
- Hyraft::Rule::SourceCommand
- Defined in:
- lib/hyraft/rule/engine/source_command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args) ⇒ SourceCommand
constructor
A new instance of SourceCommand.
Constructor Details
#initialize(args) ⇒ SourceCommand
Returns a new instance of SourceCommand.
13 14 15 16 |
# File 'lib/hyraft/rule/engine/source_command.rb', line 13 def initialize(args) @source_name = args[0] @target_dir = args[1] || "." end |
Class Method Details
.start(args) ⇒ Object
9 10 11 |
# File 'lib/hyraft/rule/engine/source_command.rb', line 9 def self.start(args) new(args).execute end |
Instance Method Details
#execute ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hyraft/rule/engine/source_command.rb', line 18 def execute return show_usage unless @source_name # Convert to singular for filename singular_name = @source_name.end_with?('s') ? @source_name[0..-2] : @source_name filename = "#{singular_name.downcase}.rb" source_dir = File.join(@target_dir, "engine/source") full_path = File.join(source_dir, filename) FileUtils.mkdir_p(source_dir) File.write(full_path, source_template(@source_name)) puts "✓ Created source: #{full_path}" end |