Class: I18n::Index::Simple
- Inherits:
-
Base
show all
- Includes:
- Storage
- Defined in:
- lib/i18n/index/simple.rb,
lib/i18n/index/simple/data.rb,
lib/i18n/index/simple/storage.rb
Defined Under Namespace
Modules: Storage
Classes: Data
Instance Attribute Summary
Attributes inherited from Base
#pattern, #root_dir
Instance Method Summary
collapse
Methods included from Storage
included
Methods inherited from Base
#filenames, #files, #initialize
Instance Method Details
36
37
38
39
40
|
# File 'lib/i18n/index/simple.rb', line 36
def data
@data ||= Data.new
build unless built?
@data
end
|
58
59
60
|
# File 'lib/i18n/index/simple/storage.rb', line 58
def delete
FileUtils.rm(filename) if exists? rescue Errno::ENOENT
end
|
#exists? ⇒ Boolean
43
44
45
|
# File 'lib/i18n/index/simple/storage.rb', line 43
def exists?
::File.exists?(filename)
end
|
62
63
64
|
# File 'lib/i18n/index/simple/storage.rb', line 62
def filename
self.class.send(:filename, :root_dir => root_dir)
end
|
#find_call(*keys) ⇒ Object
14
15
16
17
18
|
# File 'lib/i18n/index/simple.rb', line 14
def find_call(*keys)
return unless key = data.keys.detect { |key, data| key.matches?(*keys) }
occurence = data.occurences(key).first
files[occurence.filename].ruby.select_translate_calls(:position => occurence.position).first
end
|
#find_calls(*keys) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/i18n/index/simple.rb', line 20
def find_calls(*keys)
keys = data.keys.select { |key, data| key.matches?(*keys) }
occurences = keys.map { |key| data.occurences(key) }.flatten
occurences.map do |occurence|
files[occurence.filename].ruby.select_translate_calls(:position => occurence.position)
end.flatten
end
|
42
43
44
|
# File 'lib/i18n/index/simple.rb', line 42
def keys
data.keys
end
|
#marshalled_vars ⇒ Object
74
75
76
|
# File 'lib/i18n/index/simple/storage.rb', line 74
def marshalled_vars
super + [:built, :data]
end
|
70
71
72
|
# File 'lib/i18n/index/simple/storage.rb', line 70
def mkdir
FileUtils.mkdir_p(store_dir) unless ::File.exists?(store_dir)
end
|
#occurences ⇒ Object
46
47
48
|
# File 'lib/i18n/index/simple.rb', line 46
def occurences
data.values.map { |value| value[:occurences] }.flatten
end
|
#replace_key(call, search, replacement) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/i18n/index/simple.rb', line 28
def replace_key(call, search, replacement)
data.remove(call)
call.replace_key(search.to_s.gsub(/[^\w\.]/, ''), replacement.to_sym)
files[call.filename].update(call.root.src)
data.add(call)
save if built?
end
|
53
54
55
56
|
# File 'lib/i18n/index/simple/storage.rb', line 53
def save
mkdir
::File.open(filename, 'w+') { |f| ::Marshal.dump(self, f) }
end
|
#store_dir ⇒ Object
66
67
68
|
# File 'lib/i18n/index/simple/storage.rb', line 66
def store_dir
self.class.send(:store_dir, :root_dir => root_dir)
end
|
47
48
49
50
51
|
# File 'lib/i18n/index/simple/storage.rb', line 47
def update
reset!
build
save
end
|