settler 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Reinier de Lange
1
+ Copyright (c) 2011 Reinier de Lange
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -194,4 +194,4 @@ When you require this class in your application, you can easily use your typecas
194
194
 
195
195
  == Copyright
196
196
 
197
- Copyright (c) 2010 Reinier de Lange. See LICENSE for details.
197
+ Copyright (c) 2011 Reinier de Lange. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.2
@@ -1,3 +1,5 @@
1
+ # Allows us to pass a lambda to default_scope. Without this, a query can be done on the database on load time, causing an
2
+ # error when the database connection hasn't been established yet.
1
3
  module ActiveRecord
2
4
  class Base
3
5
  class << self
data/lib/setting.rb CHANGED
@@ -7,7 +7,7 @@ class Setting < ActiveRecord::Base
7
7
  self.rails3 = defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::MAJOR >= 3
8
8
 
9
9
  attr_readonly :key
10
- attr_protected :editable, :deletable, :deleted
10
+ attr_accessible :key, :alt, :value
11
11
 
12
12
  validates_presence_of :key
13
13
  validate :setting_validations
@@ -70,6 +70,10 @@ class Setting < ActiveRecord::Base
70
70
  end
71
71
  end
72
72
 
73
+ # Overrides the delete methods to ensure the default scope is not passed in the query
74
+ def delete; Setting.without_default_scope{ super } end
75
+ def self.delete_all; Setting.without_default_scope{ super } end
76
+
73
77
  # Resets this setting to the default stored in the settler configuration
74
78
  def reset!
75
79
  defaults = Settler.config[self.key]
@@ -77,6 +81,7 @@ class Setting < ActiveRecord::Base
77
81
  self.value = defaults['value']
78
82
  self.editable = defaults['editable']
79
83
  self.deletable = defaults['deletable']
84
+ self.deleted = false
80
85
  rails3 ? save(:validate => false) : save(false)
81
86
  end
82
87
 
@@ -95,9 +100,9 @@ private
95
100
  # Performs instance validations as defined in the settler configuration.
96
101
  def setting_validations
97
102
  if errors.empty?
98
- errors.add(:value, I18n.t(:blank, :scope => 'activerecord.errors.messages')) if validators['presence'] && ['1','true',true].include?(validators['presence']) && self.value.nil?
99
- errors.add(:value, I18n.t(:inclusion, :scope => 'activerecord.errors.messages')) if valid_values && !valid_values.include?(self.value)
100
- errors.add(:value, I18n.t(:invalid, :scope => 'activerecord.errors.messages')) if validators['format'] && !(Regexp.new(validators['format']) =~ self.value)
103
+ errors.add(:value, :blank) if validators['presence'] && ['1','true',true].include?(validators['presence']) && self.value.nil?
104
+ errors.add(:value, :inclusion) if valid_values && !valid_values.include?(self.value)
105
+ errors.add(:value, :invalid) if validators['format'] && !(Regexp.new(validators['format']) =~ self.value)
101
106
  end
102
107
  end
103
108
 
data/lib/settler.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'yaml'
2
2
  require 'erb'
3
3
  require 'hash_extension'
4
- require 'setting'
5
4
  require 'type_casters'
5
+ require 'setting'
6
6
 
7
7
  # Settler loads and manages application wide settings and provides an interface for retrieving settings. The Settler
8
8
  # object cannot be instantiated; all functionality is available on class level.
@@ -20,10 +20,11 @@ class Settler
20
20
  self.config = config[namespace] if namespace
21
21
  self.config.each do |key, attributes|
22
22
  Setting.without_default_scope do
23
- Setting.find_or_create_by_key(attributes.only(:alt, :value).merge(:key => key)) do |s|
23
+ setting = Setting.find_or_create_by_key(attributes.only(:alt, :value).merge(:key => key)) do |s|
24
24
  s.editable = attributes['editable']
25
25
  s.deletable = attributes['deletable']
26
26
  end
27
+ p "[Settler] Validation failed for setting '#{setting.key}': #{setting.errors.full_messages.to_sentence}" if !setting.valid?
27
28
  end
28
29
  end
29
30
  Setting.all.each{ |s| key = s.key; Settler.class.send(:define_method, key){ Setting.find_by_key(key) } }
data/settler.gemspec CHANGED
@@ -1,63 +1,54 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{settler}
8
- s.version = "1.2.1"
8
+ s.version = "1.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Reinier de Lange"]
12
- s.date = %q{2011-02-24}
12
+ s.date = %q{2011-07-27}
13
13
  s.description = %q{This gem is a combination of the Squeegy's rails-settings and Binarylogic's settingslogic gem, meaning it reads its configuration from a YAML file, but stores all settings in the database as well for on the fly changes.}
14
14
  s.email = %q{r.j.delange@nedforce.nl}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "generators/settler/settler_generator.rb",
27
- "generators/settler/templates/migration.rb",
28
- "generators/settler/templates/settler.yml",
29
- "init.rb",
30
- "lib/default_scope_patch.rb",
31
- "lib/generators/settler/USAGE",
32
- "lib/generators/settler/settler_generator.rb",
33
- "lib/generators/settler/templates/migration.rb",
34
- "lib/generators/settler/templates/settler.yml",
35
- "lib/hash_extension.rb",
36
- "lib/setting.rb",
37
- "lib/settler.rb",
38
- "lib/type_casters.rb",
39
- "settler.gemspec",
40
- "test/custom_typecaster.rb",
41
- "test/database.yml",
42
- "test/helper.rb",
43
- "test/schema.rb",
44
- "test/settler.yml",
45
- "test/test_settler.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "generators/settler/settler_generator.rb",
26
+ "generators/settler/templates/migration.rb",
27
+ "generators/settler/templates/settler.yml",
28
+ "init.rb",
29
+ "lib/default_scope_patch.rb",
30
+ "lib/generators/settler/USAGE",
31
+ "lib/generators/settler/settler_generator.rb",
32
+ "lib/generators/settler/templates/migration.rb",
33
+ "lib/generators/settler/templates/settler.yml",
34
+ "lib/hash_extension.rb",
35
+ "lib/setting.rb",
36
+ "lib/settler.rb",
37
+ "lib/type_casters.rb",
38
+ "settler.gemspec",
39
+ "test/custom_typecaster.rb",
40
+ "test/database.yml",
41
+ "test/helper.rb",
42
+ "test/schema.rb",
43
+ "test/settler.yml",
44
+ "test/test_settler.rb"
46
45
  ]
47
46
  s.homepage = %q{http://github.com/moiristo/settler}
48
- s.rdoc_options = ["--charset=UTF-8"]
49
47
  s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.3.7}
48
+ s.rubygems_version = %q{1.6.2}
51
49
  s.summary = %q{Settler manages global application settings in Rails}
52
- s.test_files = [
53
- "test/custom_typecaster.rb",
54
- "test/helper.rb",
55
- "test/schema.rb",
56
- "test/test_settler.rb"
57
- ]
58
50
 
59
51
  if s.respond_to? :specification_version then
60
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
61
52
  s.specification_version = 3
62
53
 
63
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
data/test/test_settler.rb CHANGED
@@ -23,8 +23,12 @@ class TestSettler < Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_should_not_create_instance
26
- assert_raise NoMethodError do
27
- Settler.new
26
+ if RUBY_VERSION.starts_with?("1.9")
27
+ assert_nil Settler.new
28
+ else
29
+ assert_raise NoMethodError do
30
+ Settler.new
31
+ end
28
32
  end
29
33
  end
30
34
 
@@ -51,6 +55,24 @@ class TestSettler < Test::Unit::TestCase
51
55
  assert_nil Settler.search_algorithm
52
56
  end
53
57
 
58
+ def test_should_delete_destroyed_setting
59
+ deletable_setting = Settler.search_algorithm
60
+ assert deletable_setting.destroy
61
+ deletable_setting.delete
62
+ assert Setting.deleted.empty?
63
+ Settler.load!
64
+ assert Settler.search_algorithm.present?
65
+ end
66
+
67
+ def test_should_delete_all_destroyed_setting
68
+ deletable_setting = Settler.search_algorithm
69
+ assert deletable_setting.destroy
70
+ Setting.delete_all
71
+ assert Setting.deleted.empty?
72
+ Settler.load!
73
+ assert Settler.search_algorithm.present?
74
+ end
75
+
54
76
  def test_should_not_update_uneditable_setting
55
77
  uneditable_setting = Settler.search_algorithm
56
78
  assert !uneditable_setting.update_attributes(:value => 'sphinx')
@@ -143,4 +165,12 @@ class TestSettler < Test::Unit::TestCase
143
165
  assert uneditable_setting.deletable?
144
166
  end
145
167
 
168
+ def test_should_undelete_when_resetting
169
+ deleted_setting = Settler.search_algorithm
170
+ assert deleted_setting.destroy
171
+ assert Setting.deleted.include?(deleted_setting)
172
+ deleted_setting.reset!
173
+ assert !Setting.deleted.include?(deleted_setting)
174
+ end
175
+
146
176
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 2
9
- - 1
10
- version: 1.2.1
4
+ prerelease:
5
+ version: 1.2.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - Reinier de Lange
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-02-24 00:00:00 +01:00
13
+ date: 2011-07-27 00:00:00 +02:00
19
14
  default_executable:
20
15
  dependencies: []
21
16
 
@@ -30,7 +25,6 @@ extra_rdoc_files:
30
25
  - README.rdoc
31
26
  files:
32
27
  - .document
33
- - .gitignore
34
28
  - LICENSE
35
29
  - README.rdoc
36
30
  - Rakefile
@@ -60,8 +54,8 @@ homepage: http://github.com/moiristo/settler
60
54
  licenses: []
61
55
 
62
56
  post_install_message:
63
- rdoc_options:
64
- - --charset=UTF-8
57
+ rdoc_options: []
58
+
65
59
  require_paths:
66
60
  - lib
67
61
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -69,28 +63,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
63
  requirements:
70
64
  - - ">="
71
65
  - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
66
  version: "0"
76
67
  required_rubygems_version: !ruby/object:Gem::Requirement
77
68
  none: false
78
69
  requirements:
79
70
  - - ">="
80
71
  - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
72
  version: "0"
85
73
  requirements: []
86
74
 
87
75
  rubyforge_project:
88
- rubygems_version: 1.3.7
76
+ rubygems_version: 1.6.2
89
77
  signing_key:
90
78
  specification_version: 3
91
79
  summary: Settler manages global application settings in Rails
92
- test_files:
93
- - test/custom_typecaster.rb
94
- - test/helper.rb
95
- - test/schema.rb
96
- - test/test_settler.rb
80
+ test_files: []
81
+
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC