Class: Locraft::ConstantsGenerator

Inherits:
Generator
  • Object
show all
Includes:
FileUtils
Defined in:
lib/locraft/generators/constants_generator.rb

Instance Method Summary collapse

Methods inherited from Generator

#generate, #initialize, #valid?

Constructor Details

This class inherits a constructor from Locraft::Generator

Instance Method Details

#constant_from(_key) ⇒ Object

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/locraft/generators/constants_generator.rb', line 27

def constant_from(_key)
  raise NotImplementedError
end

#constants_keys_with(localizations) ⇒ Object



21
22
23
24
25
# File 'lib/locraft/generators/constants_generator.rb', line 21

def constants_keys_with(localizations)
  localizations.select(&:valid?).map do |l|
    { key: l.key, const: constant_from(l.key) }
  end
end

#files_headerObject



31
32
33
# File 'lib/locraft/generators/constants_generator.rb', line 31

def files_header
  Utils.resource_file('macro_files_header.txt')
end

#files_nameObject



17
18
19
# File 'lib/locraft/generators/constants_generator.rb', line 17

def files_name
  @config.dev_prefix + @config.macro_file
end

#write_file_content(file, content) ⇒ Object



10
11
12
13
14
15
# File 'lib/locraft/generators/constants_generator.rb', line 10

def write_file_content(file, content)
  File.open(file, 'w+') do |f|
    f.puts files_header + "\n"
    f.puts content
  end
end