Module: RocketApi::Commands::Files

Included in:
RocketCommands
Defined in:
lib/rocket_api/commands/files.rb

Instance Method Summary collapse

Instance Method Details

#class_name_camel(name) ⇒ Object

Parameters:

  • name (String)


10
11
12
# File 'lib/rocket_api/commands/files.rb', line 10

def class_name_camel(name)
  name.split('_').map(&:capitalize).join
end

#create_single_file(name, text, **options) ⇒ Object

Parameters:

  • name (String)
  • text (String)
  • options (Hash)

Raises:

  • (StandardError)

    error



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rocket_api/commands/files.rb', line 19

def create_single_file(name, text, **options)
  raise "#{RocketApi::FILE_EXIST} #{name}" if is_exist?(name)

  out_file = File.new(name, "w")
  out_file.chmod(001) if options[:exe]
  out_file.puts(text)
  out_file.close

  puts "#{RocketApi::CREATE_SUCCESS} #{name}"
rescue StandardError => e
  raise e, "#{name} err: #{e.message}"
end

#is_exist?(dir_name) ⇒ Boolean

Parameters:

  • dir_name (String)

Returns:

  • (Boolean)


5
6
7
# File 'lib/rocket_api/commands/files.rb', line 5

def is_exist?(dir_name)
  File.exist?(dir_name)
end