Class: AwesomeTranslations::CacheDatabaseGenerator
- Inherits:
-
Object
- Object
- AwesomeTranslations::CacheDatabaseGenerator
show all
- Defined in:
- lib/awesome_translations/cache_database_generator.rb
Defined Under Namespace
Classes: Group, Handler, HandlerTranslation, ScannedFile, TranslationKey, TranslationValue
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of CacheDatabaseGenerator.
12
13
14
15
16
17
18
19
20
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 12
def initialize(args = {})
require "baza"
@args = args
@debug = @args[:debug] || false
init_database
execute_migrations
end
|
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
6
7
8
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 6
def db
@db
end
|
Class Method Details
.database_path ⇒ Object
88
89
90
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 88
def self.database_path
@database_path ||= Rails.root.join("db/awesome_translations.sqlite3").to_s
end
|
Instance Method Details
#cache_handler_translations ⇒ Object
80
81
82
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 80
def cache_handler_translations
cache_translations_in_handlers
end
|
#cache_translations ⇒ Object
60
61
62
63
64
65
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 60
def cache_translations
cache_yml_translations
cache_handler_translations
clean_up_not_found
end
|
#cache_yml_translations ⇒ Object
76
77
78
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 76
def cache_yml_translations
cache_translations_in_dir(Rails.root.join("config/locales"))
end
|
#database_path ⇒ Object
92
93
94
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 92
def database_path
@database_path ||= self.class.database_path
end
|
#initialized? ⇒ Boolean
84
85
86
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 84
def initialized?
@initialized ||= false
end
|
#update_groups_for_handler(handler_model) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 111
def update_groups_for_handler(handler_model)
@groups_found ||= {}
handler = handler_model.at_handler
handler.groups.each do |group|
debug "Updating group: #{group.name}"
group_model = AwesomeTranslations::CacheDatabaseGenerator::Group.find_or_initialize_by(
handler_id: handler_model.id,
identifier: group.id
)
group_model.assign_attributes(name: group.name)
group_model.save!
@groups_found[group_model.id] = true
group_model.at_group = group
yield group_model if block_given?
end
end
|
#update_handlers ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 96
def update_handlers
@handlers_found ||= {}
AwesomeTranslations::Handler.all.each do |handler|
debug "Updating handler: #{handler.name}"
handler_model = AwesomeTranslations::CacheDatabaseGenerator::Handler.find_or_initialize_by(identifier: handler.id)
handler_model.assign_attributes(name: handler.name)
handler_model.save!
@handlers_found[handler_model.id] = true
yield handler_model if block_given?
end
end
|
#update_translations_for_group(handler_model, group_model) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 131
def update_translations_for_group(handler_model, group_model)
group = group_model.at_group
@translation_keys_found ||= {}
@handler_translations_found ||= {}
group.translations.each do |translation|
debug "Updating translation: #{translation.key}"
translation_key = AwesomeTranslations::CacheDatabaseGenerator::TranslationKey.find_or_initialize_by(key: translation.key)
translation_key.assign_attributes(group_id: group_model.id, handler_id: handler_model.id)
translation_key.save!
raise "KEY ERROR: #{translation_key.inspect}" unless translation_key.id.to_i.positive?
@translation_keys_found[translation_key.id] = true
handler_translation = AwesomeTranslations::CacheDatabaseGenerator::HandlerTranslation.find_or_initialize_by(
translation_key_id: translation_key.id,
handler_id: handler_model.id,
group_id: group_model.id
)
handler_translation.assign_attributes(
default: translation.default,
file_path: translation.file_path,
line_no: translation.line_no,
key_show: translation.key_show,
full_path: translation.full_path,
dir: translation.dir
)
if @transactioner && handler_translation.persisted?
@transactioner.save!(handler_translation)
else
handler_translation.save!
end
@handler_translations_found[handler_translation.id] = true
end
end
|
#with_transactioner ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/awesome_translations/cache_database_generator.rb', line 67
def with_transactioner
require "active-record-transactioner"
ActiveRecordTransactioner.new do |transactioner|
@transactioner = transactioner
yield
end
end
|