Class: Config
- Inherits:
-
Object
- Object
- Config
- Defined in:
- lib/lokale/config.rb,
lib/lokale/lokalefile.rb,
lib/lokale/lokalefile.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#base_lang ⇒ Object
readonly
Returns the value of attribute base_lang.
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
-
#main_lang ⇒ Object
readonly
Returns the value of attribute main_lang.
Class Method Summary collapse
Instance Method Summary collapse
- #fill_defaults ⇒ Object
- #read_config_from_file(file_path) ⇒ Object
- #read_default_config ⇒ Object
- #read_lokalefile(project_path) ⇒ Object
- #reset_config ⇒ Object
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
20 21 22 |
# File 'lib/lokale/config.rb', line 20 def actions @actions end |
#base_lang ⇒ Object (readonly)
Returns the value of attribute base_lang.
54 55 56 |
# File 'lib/lokale/lokalefile.rb', line 54 def base_lang @base_lang end |
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
53 54 55 |
# File 'lib/lokale/lokalefile.rb', line 53 def macros @macros end |
#main_lang ⇒ Object (readonly)
Returns the value of attribute main_lang.
54 55 56 |
# File 'lib/lokale/lokalefile.rb', line 54 def main_lang @main_lang end |
Class Method Details
.get ⇒ Object
62 63 64 65 |
# File 'lib/lokale/config.rb', line 62 def self.get init if @config.nil? @config end |
.init ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lokale/config.rb', line 22 def self.init return unless @config.nil? actions = [] OptionParser.new do |opts| opts. = "Usage: lokale [-bsh]" opts.on("-b", "--copy-base", "Copies 'en' localization files to 'Base'") do |n| actions << Action.copy_base end opts.on("-s", "--summary", "Prints project summary") do |n| actions << Action.summary end opts.on("-a", "--append", "Appends new strings to english localization file") do |n| actions << Action.append end opts.on("-e", "--export", "Creates xliff files with missing localization") do |n| actions << Action.export end opts.on("-i", "--import", "Looks for xliffs in project dir and imports whatever possible") do |n| actions << Action.import end opts.on("-h", "--help", "Prints this help") do puts opts exit end end.parse! actions << Action.summary if actions.empty? @config = Config.new @config.actions = actions end |
Instance Method Details
#fill_defaults ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/lokale/lokalefile.rb', line 62 def fill_defaults default = Config.new default.read_default_config @macros ||= default.macros @main_lang ||= default.main_lang @base_lang ||= default.base_lang end |
#read_config_from_file(file_path) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/lokale/lokalefile.rb', line 42 def read_config_from_file(file_path) content = File.read(file_path) reset_config instance_eval(content) fill_defaults end |
#read_default_config ⇒ Object
37 38 39 40 |
# File 'lib/lokale/lokalefile.rb', line 37 def read_default_config reset_config instance_eval(DEFAULT_LOKALEFILE) end |
#read_lokalefile(project_path) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/lokale/lokalefile.rb', line 27 def read_lokalefile(project_path) lokalefile_path = File.join(project_path, ".lokale") if File.file? lokalefile_path read_config_from_file(lokalefile_path) else read_default_config end end |
#reset_config ⇒ Object
56 57 58 59 60 |
# File 'lib/lokale/lokalefile.rb', line 56 def reset_config @macros = nil @main_lang = nil @base_lang = nil end |