Class: Locraft::ConstantsGenerator

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

Instance Method Summary collapse

Constructor Details

#initialize(config, localizations) ⇒ ConstantsGenerator

Returns a new instance of ConstantsGenerator.



8
9
10
11
# File 'lib/locraft/generators/constants_generator.rb', line 8

def initialize(config, localizations)
  @config = config
  @localizations = localizations
end

Instance Method Details

#constant_from(_key) ⇒ Object

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/locraft/generators/constants_generator.rb', line 34

def constant_from(_key)
  raise NotImplementedError
end

#constants_keysObject



28
29
30
31
32
# File 'lib/locraft/generators/constants_generator.rb', line 28

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

#files_headerObject



38
39
40
# File 'lib/locraft/generators/constants_generator.rb', line 38

def files_header
  resource_file('macro_files_header.txt')
end

#files_nameObject



24
25
26
# File 'lib/locraft/generators/constants_generator.rb', line 24

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

#generateObject

Raises:

  • (NotImplementedError)


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

def generate
  raise NotImplementedError
end

#resource_file(file) ⇒ Object



42
43
44
# File 'lib/locraft/generators/constants_generator.rb', line 42

def resource_file(file)
  File.read(File.expand_path("../../resources/#{file}", __FILE__))
end

#write_file_content(file, content) ⇒ Object



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

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