glib-web 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a318fa9377a19b89642be242b820ee9e2670f0bff29e6a346806b76f8906b16f
4
- data.tar.gz: 8797bfd1ab030db735284adcf8c9ddf86441dbd0b189273ca8e7cd0f4d8cdd57
3
+ metadata.gz: b13a0d5398903f6b1e6795d7a34dce9c064dd05a7df740d47cd15690fdd906eb
4
+ data.tar.gz: 4195513ba393a6d4f0fff811f01355b2aef1793caf3c3fb7d609d3df3d31cfc2
5
5
  SHA512:
6
- metadata.gz: dfe9421dcc2b4897220d5a7cea9ef1e258bbfbd9a4667b5a5c40e0a39876f7cc666b40b4b0f0efe4d3efb8020d888542d1757d625cf83b3cabcb53a6a27787e6
7
- data.tar.gz: 3f6abcd4c53f2abd78b7a96c539c59dec16559147502b28ba3d4fb80f2bdea756a3e51f887082429043d8322bba4d75bb318fcaef27a1ffac121708aa4012d6e
6
+ metadata.gz: 7162957076123f6f803f6c854f1099bf1e44f1ff27c7900d24ef3eb3ab259491459c3071a343683d800cab007d744d7ddfe0fba31e47c4b09fd8e32abcbb0e1e
7
+ data.tar.gz: 816b64172b98f4e1907894b93265adad533d319b0561fe2f73439d0c47c7e9da52a67d0bf6eb7a94a5d54ca50755e88ae2a6f143e6bc08324b2e486f5c981d1e
@@ -1,12 +1,13 @@
1
1
  module Glib
2
2
  module DynamicTextsHelper
3
- def dt(key, default_value = '', scope = 'itinerarybuilder')
3
+ def dt(key, default_value = '', options: { scope: 'itinerarybuilder', lang: 'en' })
4
4
  new_key = key
5
+
5
6
  if key.starts_with?('.')
6
7
  new_key = "#{controller_name}.#{action_name}#{key}"
7
8
  end
8
9
 
9
- Glib::Text.get_content(scope, new_key, default_value)
10
+ Glib::Text.get_content(new_key, default_value, options: options)
10
11
  end
11
12
  end
12
13
  end
@@ -1,20 +1,21 @@
1
1
  module Glib
2
2
  class Text < Glib::DynamicTextRecord
3
3
  validates :scope, presence: true
4
- validates :key, presence: true, uniqueness: { scope: :scope }
4
+ validates :lang, presence: true
5
+ validates :key, presence: true, uniqueness: { scope: [:scope, :lang] }
5
6
  validates :content, presence: true
6
7
 
7
8
  after_save :update_to_redis
8
9
 
9
- def self.get_content(scope, key, default_value)
10
- scope_key = "#{scope}.#{key}"
10
+ def self.get_content(key, default_value, options:)
11
+ scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
11
12
 
12
13
  unless content = $dt_redis.get(scope_key)
13
- if text = find_by(scope: scope, key: key)
14
+ if text = find_by(scope: options[:scope], lang: options[:lang], key: key)
14
15
  update_content(scope_key, text.content)
15
16
  content = text.content
16
17
  else
17
- create(scope: scope, key: key, content: default_value)
18
+ create(scope: options[:scope], lang: options[:lang], key: key, content: default_value)
18
19
  update_content(scope_key, default_value)
19
20
  content = default_value
20
21
  end
@@ -29,7 +30,7 @@ module Glib
29
30
  end
30
31
 
31
32
  def update_to_redis
32
- Glib::Text.update_content("#{scope}.#{key}", content)
33
+ Glib::Text.update_content("#{scope}.#{lang}.#{key}", content)
33
34
  end
34
35
  end
35
36
  end
@@ -10,6 +10,7 @@ module Glib
10
10
  def copy_initializer
11
11
  template '20191017062519_create_texts.rb', 'db/dynamic_text_migrate/20191017062519_create_texts.rb'
12
12
  template '20191024063257_add_scope_to_texts.rb', 'db/dynamic_text_migrate/20191024063257_add_scope_to_texts.rb'
13
+ template '20191112095018_add_lang_to_texts.rb', 'db/dynamic_text_migrate/20191112095018_add_lang_to_texts.rb'
13
14
  template 'dynamic_text.rb', 'config/initializers/dynamic_text.rb'
14
15
  template 'database.yml', 'config/database.yml'
15
16
  end
@@ -0,0 +1,7 @@
1
+ class AddLangToTexts < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :texts, :lang, :string
4
+ remove_index :texts, [:scope, :key]
5
+ add_index :texts, [:scope, :lang, :key], unique: true
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -117,6 +117,7 @@ files:
117
117
  - lib/generators/glib/install_generator.rb
118
118
  - lib/generators/templates/20191017062519_create_texts.rb
119
119
  - lib/generators/templates/20191024063257_add_scope_to_texts.rb
120
+ - lib/generators/templates/20191112095018_add_lang_to_texts.rb
120
121
  - lib/generators/templates/database.yml
121
122
  - lib/generators/templates/dynamic_text.rb
122
123
  - lib/glib-web.rb