lit 0.0.3.1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ module Lit
9
9
  end
10
10
 
11
11
  def update
12
- if @localization.update_attributes(params[:localization])
12
+ if @localization.update_attributes(clear_params)
13
13
  Lit.init.cache.refresh_key @localization.full_key
14
14
  end
15
15
  respond_to :js
@@ -23,5 +23,13 @@ module Lit
23
23
  def find_localization
24
24
  @localization = @localization_key.localizations.find(params[:id])
25
25
  end
26
+
27
+ def clear_params
28
+ if ::Rails::VERSION::MAJOR>=4
29
+ params[:localization].permit(:translated_value, :locale_id)
30
+ else
31
+ params[:localization]
32
+ end
33
+ end
26
34
  end
27
35
  end
@@ -2,7 +2,7 @@ module Lit
2
2
  class Locale < ActiveRecord::Base
3
3
 
4
4
  ## SCOPES
5
- scope :ordered, order('locale ASC')
5
+ scope :ordered, proc{ order('locale ASC') }
6
6
 
7
7
  ## ASSOCIATIONS
8
8
  has_many :localizations, :dependent=>:destroy
@@ -12,8 +12,10 @@ module Lit
12
12
  :presence=>true,
13
13
  :uniqueness=>true
14
14
 
15
- ## ACCESSIBLE
16
- attr_accessible :locale
15
+ if ::Rails::VERSION::MAJOR<4
16
+ ## ACCESSIBLE
17
+ attr_accessible :locale
18
+ end
17
19
 
18
20
  def to_s
19
21
  self.locale
@@ -2,7 +2,7 @@ module Lit
2
2
  class Localization < ActiveRecord::Base
3
3
 
4
4
  ## SCOPES
5
- scope :changed, where(:is_changed=>true)
5
+ scope :changed, proc{ where(:is_changed=>true) }
6
6
 
7
7
  ## ASSOCIATIONS
8
8
  belongs_to :locale
@@ -12,8 +12,10 @@ module Lit
12
12
  validates :locale_id,
13
13
  :presence=>true
14
14
 
15
- ## ACCESSIBLE
16
- attr_accessible :translated_value, :locale_id
15
+ if ::Rails::VERSION::MAJOR<4
16
+ ## ACCESSIBLE
17
+ attr_accessible :translated_value, :locale_id
18
+ end
17
19
 
18
20
  ## BEFORE & AFTER
19
21
  before_update :update_is_changed
@@ -2,10 +2,10 @@ module Lit
2
2
  class LocalizationKey < ActiveRecord::Base
3
3
 
4
4
  ## SCOPES
5
- scope :completed, where(:is_completed=>true)
6
- scope :not_completed, where(:is_completed=>false)
7
- scope :starred, where(:is_starred=>true)
8
- scope :ordered, order('localization_key asc')
5
+ scope :completed, proc{ where(:is_completed=>true) }
6
+ scope :not_completed, proc{ where(:is_completed=>false) }
7
+ scope :starred, proc{ where(:is_starred=>true) }
8
+ scope :ordered, proc{ order('localization_key asc') }
9
9
 
10
10
  ## ASSOCIATIONS
11
11
  has_many :localizations, :dependent=>:destroy
@@ -15,8 +15,10 @@ module Lit
15
15
  :presence=>true,
16
16
  :uniqueness=>true
17
17
 
18
- ## ACCESSIBLE
19
- attr_accessible :localization_key
18
+ if ::Rails::VERSION::MAJOR<4
19
+ ## ACCESSIBLE
20
+ attr_accessible :localization_key
21
+ end
20
22
 
21
23
  def to_s
22
24
  self.localization_key
@@ -1,6 +1,6 @@
1
1
  Lit::Engine.routes.draw do
2
2
 
3
- resources :localization_keys, :actions=>[:index, :destroy] do
3
+ resources :localization_keys, :only=>[:index, :destroy] do
4
4
  member do
5
5
  get :star
6
6
  end
data/lib/lit.rb CHANGED
@@ -4,6 +4,7 @@ require 'lit/loader'
4
4
  module Lit
5
5
  mattr_accessor :authentication_function
6
6
  mattr_accessor :key_value_engine
7
+ mattr_accessor :storage_options
7
8
  class << self
8
9
  attr_accessor :loader
9
10
  end
@@ -13,6 +14,7 @@ module Lit
13
14
  #if loading all translations on start, migrations have to be performed
14
15
  #already, fails on first deploy
15
16
  #self.loader.cache.load_all_translations
17
+ Lit.storage_options ||= {}
16
18
  end
17
19
  self.loader
18
20
  end
@@ -12,24 +12,33 @@ module Lit
12
12
  end
13
13
 
14
14
  def [](key)
15
- Lit.redis.get(key)
15
+ Lit.redis.get(_prefixed_key(key))
16
16
  end
17
17
 
18
18
  def []=(k, v)
19
- Lit.redis.set(k.to_s, v.to_s)
19
+ Lit.redis.set(_prefixed_key(k).to_s, v.to_s)
20
20
  end
21
21
 
22
22
  def clear
23
- Lit.redis.flushall
23
+ Lit.redis.del self.keys
24
24
  save
25
25
  end
26
26
 
27
27
  def keys
28
- Lit.redis.keys
28
+ Lit.redis.keys(_prefixed_key+"*")
29
29
  end
30
30
 
31
31
  def has_key?(key)
32
- Lit.redis.exists(key)
32
+ Lit.redis.exists(_prefixed_key(key))
33
33
  end
34
+
35
+ private
36
+ def _prefixed_key(key="")
37
+ prefix = "lit:"
38
+ if Lit.storage_options.is_a?(Hash)
39
+ prefix += "#{Lit.storage_options[:prefix]}:" if Lit.storage_options.has_key?(:prefix)
40
+ end
41
+ prefix+key
42
+ end
34
43
  end
35
44
  end
@@ -43,8 +43,6 @@ module Lit
43
43
  locale_key, key_without_locale = split_key(key)
44
44
  locale = find_locale(locale_key)
45
45
  localization = find_localization(locale, key_without_locale)
46
- puts @localizations.class
47
- Lit.init.logger.info @localizations.class
48
46
  @localizations[key] = localization.get_value
49
47
  end
50
48
 
@@ -121,7 +119,7 @@ module Lit
121
119
  end
122
120
  end
123
121
  l.default_value = value
124
- Lit.init.logger.info "creating new localization: #{key_without_locale}"
122
+ #Lit.init.logger.info "creating new localization: #{key_without_locale}"
125
123
  #Lit.init.logger.info "creating new localization with value: #{value}"
126
124
  #Lit.init.logger.info "creating new localization with value: #{value.class}"
127
125
  create = true
@@ -28,7 +28,7 @@ module Lit
28
28
  # @param [Hash] options unused part of the I18n API
29
29
  def store_translations(locale, data, options = {})
30
30
  super
31
- Lit.init.logger.info "store translation: #{locale}, data: #{data}, options: #{options}"
31
+ #Lit.init.logger.info "store translation: #{locale}, data: #{data}, options: #{options}"
32
32
  store_item(locale, data)
33
33
  end
34
34
 
@@ -36,7 +36,7 @@ module Lit
36
36
  private
37
37
 
38
38
  def lookup(locale, key, scope = [], options = {})
39
- Lit.init.logger.info "lookup translation: #{key}, scope: #{scope}, options: #{options}"
39
+ #Lit.init.logger.info "lookup translation: #{key}, scope: #{scope}, options: #{options}"
40
40
  parts = I18n.normalize_keys(locale, key, scope, options[:separator])
41
41
  key_with_locale = parts.join('.')
42
42
  content = @cache[key_with_locale] || super
@@ -1,3 +1,3 @@
1
1
  module Lit
2
- VERSION = "0.0.3.1"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.1
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - ! '>'
52
52
  - !ruby/object:Gem::Version
53
53
  version: '3.1'
54
54
  type: :runtime
@@ -56,7 +56,7 @@ dependencies:
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ~>
59
+ - - ! '>'
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.1'
62
62
  - !ruby/object:Gem::Dependency