Class: Devkitkat::Service::PredefinedCommand::AddExample

Inherits:
Base
  • Object
show all
Defined in:
lib/devkitkat/service/predefined_command/add_example.rb

Instance Attribute Summary

Attributes included from Concerns::ServiceInitializer

#service

Instance Method Summary collapse

Methods included from Concerns::ServiceInitializer

#initialize

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/devkitkat/service/predefined_command/add_example.rb', line 26

def available?
  true
end

#machine_driverObject



30
31
32
# File 'lib/devkitkat/service/predefined_command/add_example.rb', line 30

def machine_driver
  'none'
end

#to_scriptObject

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/devkitkat/service/predefined_command/add_example.rb', line 7

def to_script
  names = command.args

  raise ArgumentError, 'Please specify at least one example name' if names.empty?

  FileUtils.mkdir_p(service.example_dir)

  names.map do |name|
    file_path = File.join(service.example_dir, name)

    <<-EOS
if [[ ! -f "#{file_path}" ]]; then
  touch #{file_path}
  chmod 755 #{file_path}
fi
    EOS
  end.join("\n")
end