Class: I18n::Index::File
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
- #calls ⇒ Object
-
#initialize(filename) ⇒ File
constructor
A new instance of File.
- #ruby ⇒ Object
- #save ⇒ Object
- #source ⇒ Object
- #update(source) ⇒ Object
Constructor Details
#initialize(filename) ⇒ File
Returns a new instance of File.
14 15 16 |
# File 'lib/i18n/index/file.rb', line 14 def initialize(filename) self.filename = filename end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
12 13 14 |
# File 'lib/i18n/index/file.rb', line 12 def filename @filename end |
Instance Method Details
#calls ⇒ Object
35 36 37 |
# File 'lib/i18n/index/file.rb', line 35 def calls @calls ||= ruby.select_translate_calls end |
#ruby ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/i18n/index/file.rb', line 26 def ruby @ruby ||= begin parser.parse rescue Ripper::RubyBuilder::ParseError => e puts "\nWARNING Ruby 1.9 incompatible syntax in: " + e..gsub(Dir.pwd, '') + ". Can not index file." Ruby::Program.new(source, filename) end end |
#save ⇒ Object
44 45 46 |
# File 'lib/i18n/index/file.rb', line 44 def save ::File.open(filename, 'w+') { |f| f.write(source) } # TODO need to modify/write unfiltered source for ERB end |
#source ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/i18n/index/file.rb', line 18 def source @source ||= begin source = ::File.read(filename) # TODO srsly ... how am i supposed to open a file in ruby 1.9? source = ::File.open(filename, 'r:iso-8859-1:utf-8') { |f| f.read } unless source.valid_encoding? source end end |
#update(source) ⇒ Object
39 40 41 42 |
# File 'lib/i18n/index/file.rb', line 39 def update(source) @source = source save end |