sequel_translatable 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,12 +13,12 @@ module Sequel
13
13
  send "#{attribute}_\#{base_locale}"
14
14
  end
15
15
  def #{attribute}_hash
16
- @#{attribute}_columns ||= columns.collect do |column|
16
+ @#{attribute}_locales ||= columns.collect do |column|
17
17
  $1 if column=~/\\A#{Regexp.escape attribute}_(.+)\\z/
18
18
  end.compact.sort.collect(&:to_sym)
19
19
  hash = {}
20
- @#{attribute}_columns.each do |column|
21
- hash[column] = send "#{attribute}_\#{column}"
20
+ @#{attribute}_locales.each do |locale|
21
+ hash[locale] = send "#{attribute}_\#{locale}"
22
22
  end
23
23
  hash
24
24
  end
@@ -30,6 +30,12 @@ module Sequel
30
30
  module DatasetMethods
31
31
  end
32
32
  module InstanceMethods
33
+ def validates_at_least_one_language(attribute)
34
+ hash = send "#{attribute}_hash"
35
+ hash.keys.each do |locale|
36
+ errors.add :"#{attribute}_#{locale}", "at least one language is required"
37
+ end if hash.values.all?{|value| value.to_s.strip.empty?}
38
+ end
33
39
  private
34
40
  def base_locale
35
41
  I18n.locale.to_s[0..1]
@@ -37,4 +43,4 @@ module Sequel
37
43
  end
38
44
  end
39
45
  end
40
- end
46
+ end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "sequel_translatable"
6
- s.version = "0.1.0"
6
+ s.version = "0.2.0"
7
7
  s.authors = ["Joseph HALTER"]
8
8
  s.email = ["joseph.halter@thetalentbox.com"]
9
9
  s.homepage = "https://github.com/TalentBox/sequel_translatable"
@@ -15,8 +15,9 @@ Gem::Specification.new do |s|
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ["lib"]
17
17
 
18
+ s.add_development_dependency "rake"
18
19
  s.add_development_dependency "sqlite3"
19
20
  s.add_development_dependency "rspec"
20
21
  s.add_runtime_dependency "i18n"
21
22
  s.add_runtime_dependency "sequel"
22
- end
23
+ end
@@ -51,4 +51,19 @@ describe "Sequel::Plugins::Translatable" do
51
51
  m.value_en.should == "Objects"
52
52
  m.value_hash.should == {en: "Objects", fr: "Objets"}
53
53
  end
54
- end
54
+ it "allows validating at least one language is required" do
55
+ @klass.plugin :translatable, :value
56
+ @klass.send :define_method, :validate do
57
+ super()
58
+ validates_at_least_one_language :value
59
+ end
60
+ m = @klass.new
61
+ m.should_not be_valid
62
+ m.errors.should == {
63
+ value_en: ["at least one language is required"],
64
+ value_fr: ["at least one language is required"],
65
+ }
66
+ m.value = "Objects"
67
+ m.should be_valid
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_translatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-07 00:00:00.000000000Z
12
+ date: 2012-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2156906180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2156906180
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: sqlite3
16
- requirement: &2157761100 !ruby/object:Gem::Requirement
27
+ requirement: &2156904080 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *2157761100
35
+ version_requirements: *2156904080
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- requirement: &2157760660 !ruby/object:Gem::Requirement
38
+ requirement: &2156902780 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *2157760660
46
+ version_requirements: *2156902780
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: i18n
38
- requirement: &2157760240 !ruby/object:Gem::Requirement
49
+ requirement: &2156917640 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :runtime
45
56
  prerelease: false
46
- version_requirements: *2157760240
57
+ version_requirements: *2156917640
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: sequel
49
- requirement: &2157759820 !ruby/object:Gem::Requirement
60
+ requirement: &2156916340 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :runtime
56
67
  prerelease: false
57
- version_requirements: *2157759820
68
+ version_requirements: *2156916340
58
69
  description: Translate model attributes for sequel, fully tested.
59
70
  email:
60
71
  - joseph.halter@thetalentbox.com
@@ -83,15 +94,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
94
  - - ! '>='
84
95
  - !ruby/object:Gem::Version
85
96
  version: '0'
97
+ segments:
98
+ - 0
99
+ hash: -3733927863108419212
86
100
  required_rubygems_version: !ruby/object:Gem::Requirement
87
101
  none: false
88
102
  requirements:
89
103
  - - ! '>='
90
104
  - !ruby/object:Gem::Version
91
105
  version: '0'
106
+ segments:
107
+ - 0
108
+ hash: -3733927863108419212
92
109
  requirements: []
93
110
  rubyforge_project:
94
- rubygems_version: 1.8.6
111
+ rubygems_version: 1.8.10
95
112
  signing_key:
96
113
  specification_version: 3
97
114
  summary: Translate model attributes for sequel.