arsettings 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,27 +10,27 @@ task :default => :test
10
10
  namespace :test do
11
11
  desc 'create the gemsets'
12
12
  task :make_gemsets do
13
- sh File.dirname(__FILE__) << "/test/_make_gemsets.sh"
13
+ sh File.dirname(__FILE__) << "/script/_make_gemsets.sh"
14
14
  end
15
15
 
16
16
  desc 'run the tests on current ruby/gemspec'
17
17
  task :crnt do
18
- require File.dirname(__FILE__) << "/test/_run_one"
18
+ require File.dirname(__FILE__) << "/script/_run_one"
19
19
  end
20
20
 
21
21
  desc 'check that all code is covered'
22
22
  task :rcov do
23
- sh File.dirname(__FILE__) << "/test/_rcov.sh"
23
+ sh File.dirname(__FILE__) << "/script/_rcov.sh"
24
24
  end
25
25
 
26
26
  desc 'run the tests on the supported rubies and gemsets'
27
27
  task :all do
28
- sh File.dirname(__FILE__) << "/test/_run_all.sh"
28
+ sh File.dirname(__FILE__) << "/script/_run_all.sh"
29
29
  end
30
30
 
31
31
  desc 'checks for code smells -- assumes you have reek installed'
32
32
  task :reek do
33
- sh File.dirname(__FILE__) << "/test/_reek.sh"
33
+ sh File.dirname(__FILE__) << "/script/_reek.sh"
34
34
  end
35
35
  end
36
36
 
@@ -56,7 +56,7 @@ spec = Gem::Specification.new do |s|
56
56
 
57
57
  # Change these as appropriate
58
58
  s.name = "arsettings"
59
- s.version = "1.1.1"
59
+ s.version = "1.1.2"
60
60
  s.author = "Joshua Cheek"
61
61
  s.email = "josh.cheek@gmail.com"
62
62
  s.homepage = "https://github.com/JoshCheek/ARSettings"
@@ -68,7 +68,7 @@ spec = Gem::Specification.new do |s|
68
68
  s.rdoc_options = %w(--main Readme.mdown)
69
69
 
70
70
  # Add any extra files to include in the gem
71
- s.files = %w(Rakefile Readme.mdown) + Dir.glob("{examples/**/*,test/**/*,lib/**/*}")
71
+ s.files = %w(Rakefile Readme.mdown) + Dir.glob("{examples/**/*,test/**/*,lib/**/*,script/**/*}")
72
72
  s.require_paths = ["lib"]
73
73
 
74
74
  # If you want to depend on other gems, add them here, along with any
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../lib/arsettings'
3
3
 
4
4
  # tell it to create us a settings class named Settings
5
5
  # this means you must have a table in your db named 'settings'
6
- ARSettings.create_settings_class 'Settings'
6
+ ARSettings.create 'Settings'
7
7
 
8
8
  # add and change a setting
9
9
  Settings.has_setting :domain , :default => 'localhost:3000'
@@ -21,3 +21,13 @@ rescue ARSettings::UninitializedSettingError
21
21
  end
22
22
  Settings.port = 3000
23
23
  Settings.port # => 3000
24
+
25
+
26
+ # for performance, can specify volatility to be false
27
+ # if the setting is volatile, it could be changed by something
28
+ # other than this code (ie you in the console, or another instance of your app)
29
+ # so **ARSettings reloads the setting from the db each time you ask for it.**
30
+ # if volatile is false, it only touches the db when initially loading the setting
31
+ # or when saving the setting after updating it
32
+ Settings.has_setting :site_name , :volatile => false
33
+
@@ -6,22 +6,19 @@ require 'active_record'
6
6
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3' , :database => ":memory:"
7
7
 
8
8
 
9
- # silently create the db
10
- require 'stringio'
11
- $stdout = StringIO.new
12
-
9
+ # create the db
13
10
  ActiveRecord::Schema.define do
14
- create_table :settings do |t|
15
- t.string :name , :null => false , :size => 30
16
- t.text :value
17
- t.text :package
18
- t.boolean :volatile , :default => false
19
- t.timestamps
20
- end
11
+ suppress_messages do
12
+ create_table :settings do |t|
13
+ t.string :name , :null => false , :size => 30
14
+ t.text :value
15
+ t.text :package
16
+ t.boolean :volatile , :default => false
17
+ t.timestamps
18
+ end
21
19
 
22
- create_table :users do |t|
23
- t.string :name
20
+ create_table :users do |t|
21
+ t.string :name
22
+ end
24
23
  end
25
24
  end
26
-
27
- $stdout = STDOUT
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../lib/arsettings'
3
3
 
4
4
  # tell it to create us a settings class named Settings
5
5
  # this means you must have a table in your db named 'settings'
6
- ARSettings.create_settings_class 'Settings'
6
+ ARSettings.create 'Settings'
7
7
 
8
8
 
9
9
  # you can package settings together under a namespace
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../lib/arsettings'
3
3
 
4
4
  # tell it to create us a settings class named Settings
5
5
  # this means you must have a table in your db named 'settings'
6
- ARSettings.create_settings_class 'Settings'
6
+ ARSettings.create 'Settings'
7
7
 
8
8
  class User < ActiveRecord::Base
9
9
  has_setting(:site_admin) { |user| user.name }
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../lib/arsettings'
3
3
 
4
4
  # tell it to create us a settings class named Settings
5
5
  # this means you must have a table in your db named 'settings'
6
- ARSettings.create_settings_class 'Settings'
6
+ ARSettings.create 'Settings'
7
7
 
8
8
 
9
9
  class Water
@@ -16,8 +16,8 @@ module ARSettings
16
16
  klass = Object.const_get(classname).class_eval do
17
17
  extend SettingsClass::ClassMethods
18
18
  include SettingsClass::InstanceMethods
19
- const_set :MAX_CHARS , options.fetch( :max_chars , 30 )
20
- const_set :VOLATILIE_DEFAULT , options.fetch( :volatile , false )
19
+ const_set :MAX_CHARS , options.fetch( :max_chars , 30 )
20
+ const_set :VOLATILIE_DEFAULT , options.fetch( :volatile , true )
21
21
  send :load_from_db
22
22
  self
23
23
  end
@@ -114,7 +114,7 @@ module ARSettings
114
114
  end
115
115
 
116
116
  def remove_method(name) # :nodoc:
117
- metaclass.send :remove_method , "#{setting}="
117
+ metaclass.send :remove_method , name
118
118
  end
119
119
 
120
120
  def add_setter(name) # :nodoc:
@@ -132,22 +132,23 @@ module ARSettings
132
132
  end
133
133
 
134
134
  def remove_setter(name) # :nodoc:
135
- metaclass.send :remove_method , "#{name}="
135
+ remove_method "#{name}="
136
136
  end
137
137
 
138
138
  def remove_getter(name) # :nodoc:
139
- metaclass.send :remove_method , name
139
+ remove_method name
140
140
  end
141
141
 
142
142
  def remove_boolean_getter(name) # :nodoc:
143
- metaclass.send :remove_method , "#{name}?"
143
+ remove_method "#{name}?"
144
144
  end
145
145
 
146
146
  def method_missing(name,*args) # :nodoc:
147
- if name.to_s =~ /\A[A-Z]/
147
+ name_to_s = name.to_s
148
+ if name_to_s =~ /\A[A-Z]/
148
149
  settings_class.const_get name , *args
149
- elsif name.to_s !~ /=$/ || ( name.to_s =~ /=$/ && args.size == 1 )
150
- raise ARSettings::NoSuchSettingError.new("There is no setting named #{name.to_s.chomp '='}")
150
+ elsif name_to_s !~ /=$/ || ( name_to_s =~ /=$/ && args.size == 1 )
151
+ raise ARSettings::NoSuchSettingError.new("There is no setting named #{name_to_s.chomp '='}")
151
152
  else
152
153
  super
153
154
  end
File without changes
File without changes
File without changes
@@ -7,5 +7,5 @@ for rvm_set in 1.8.6-2.3.3 1.8.6-2.3.5 1.8.6-2.3.8 1.8.7-2.3.3 1.8.7-2.3.5 1.8.7
7
7
  ruby_version=${arr[0]}
8
8
  ar_version=${arr[1]}
9
9
  rvm use "$ruby_version@ruby$ruby_version-activerecord$ar_version"
10
- ./test/_run_one.rb
10
+ ./script/_run_one.rb
11
11
  done
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ query = File.dirname(__FILE__) << '/../test/*_test.rb'
3
+ Dir[query].each { |filename| require filename }
@@ -58,6 +58,8 @@ ActiveRecord::Schema.define do
58
58
  :setting24s ,
59
59
  :setting25s ,
60
60
  :volatile_tests ,
61
+ :volatile_test2s ,
62
+ :default_volatiles ,
61
63
  :this_should_be_returneds ,
62
64
  ].flatten.each do |tablename|
63
65
  create_table tablename , &define_as_settings_class
@@ -67,7 +67,7 @@ class ActiveRecordIntegration < Test::Unit::TestCase
67
67
  $sql_executor.silent_execute "update settings set value='#{ARSettings.serialize(200.0)}' where name='ijkl'"
68
68
  assert_equal 200 , @klass.abcd
69
69
  assert_equal 14.0 , @klass.efgh
70
- assert_equal '14' , @klass.ijkl
70
+ assert_equal 200.0 , @klass.ijkl
71
71
  end
72
72
 
73
73
  verify 'two classes dont see eachothers settings' do
@@ -88,7 +88,7 @@ class AddToArbitraryClass < Test::Unit::TestCase
88
88
  $sql_executor.silent_execute "update setting15s set value='#{ARSettings.serialize(200.0)}' where name='ijkl'"
89
89
  assert_equal 200 , C6.abcd
90
90
  assert_equal 14.0 , C6.efgh
91
- assert_equal '14' , C6.ijkl
91
+ assert_equal 200.0 , C6.ijkl
92
92
  end
93
93
 
94
94
  verify 'two classes dont see eachothers settings' do
@@ -138,7 +138,7 @@ class TestPackaging < Test::Unit::TestCase
138
138
  end
139
139
 
140
140
  verify 'can specify that object should reload from db each time' do
141
- s.add :abcd , :default => 1
141
+ s.add :abcd , :default => 1 , :volatile => false
142
142
  s.add :efgh , :default => 10 , :volatile => true
143
143
  assert_equal 1 , s.abcd
144
144
  assert_equal 10 , s.efgh
@@ -26,6 +26,14 @@ class InitializingSettingsClasses < Test::Unit::TestCase
26
26
  PredefinedValues.add :predefined_value , :default => 20
27
27
  assert_equal 12 , PredefinedValues.predefined_value
28
28
  end
29
+
30
+ verify 'volatile is false by default' do
31
+ ARSettings.create_settings_class :DefaultVolatile
32
+ DefaultVolatile.add :efgh , :default => 10
33
+ assert_equal 10 , DefaultVolatile.efgh
34
+ $sql_executor.silent_execute "update default_volatiles set value='#{ARSettings.serialize(20)}' where name='efgh'"
35
+ assert_equal 20 , DefaultVolatile.efgh
36
+ end
29
37
 
30
38
  verify 'can specify a volatility default' do
31
39
  ARSettings.create_settings_class :VolatileTest , :volatile => true
@@ -41,6 +49,20 @@ class InitializingSettingsClasses < Test::Unit::TestCase
41
49
  assert_equal 1 , VolatileTest.abcd
42
50
  assert_equal 20 , VolatileTest.efgh
43
51
  assert_equal 200 , VolatileTest.ijkl
52
+
53
+ ARSettings.create_settings_class :VolatileTest2 , :volatile => false
54
+ VolatileTest2.add :abcd , :default => 1 , :volatile => false
55
+ VolatileTest2.add :efgh , :default => 10 , :volatile => true
56
+ VolatileTest2.add :ijkl , :default => 100
57
+ assert_equal 1 , VolatileTest2.abcd
58
+ assert_equal 10 , VolatileTest2.efgh
59
+ assert_equal 100 , VolatileTest2.ijkl
60
+ $sql_executor.silent_execute "update volatile_test2s set value='#{ARSettings.serialize(2)}' where name='abcd'"
61
+ $sql_executor.silent_execute "update volatile_test2s set value='#{ARSettings.serialize(20)}' where name='efgh'"
62
+ $sql_executor.silent_execute "update volatile_test2s set value='#{ARSettings.serialize(200)}' where name='ijkl'"
63
+ assert_equal 1 , VolatileTest2.abcd
64
+ assert_equal 20 , VolatileTest2.efgh
65
+ assert_equal 100 , VolatileTest2.ijkl
44
66
  end
45
67
 
46
68
  verify 'create_settings_class should return the class' do
@@ -80,15 +80,19 @@ class SettingTest < Test::Unit::TestCase
80
80
  assert_equal [[:abc,1],[:def,2],[:ghi,3]] , Setting.settings_with_values.sort_by { |name,value| name.to_s }
81
81
  end
82
82
 
83
- verify 'can specify that object should reload from db each time' do
84
- Setting.add :abcd , :default => 1
85
- Setting.add :efgh , :default => 10 , :volatile => true
83
+ verify 'can specify that object should or shouldnt reload from db each time, with default being to do so' do
84
+ Setting.add :abcd , :default => 1 , :volatile => false
85
+ Setting.add :efgh , :default => 10 , :volatile => true
86
+ Setting.add :ijkl , :default => 100
86
87
  assert_equal 1 , Setting.abcd
87
88
  assert_equal 10 , Setting.efgh
89
+ assert_equal 100 , Setting.ijkl
88
90
  $sql_executor.silent_execute "update settings set value='#{ARSettings.serialize(2)}' where name='abcd'"
89
91
  $sql_executor.silent_execute "update settings set value='#{ARSettings.serialize(20)}' where name='efgh'"
90
- assert_equal 1 , Setting.abcd
91
- assert_equal 20 , Setting.efgh
92
+ $sql_executor.silent_execute "update settings set value='#{ARSettings.serialize(200)}' where name='ijkl'"
93
+ assert_equal 1 , Setting.abcd
94
+ assert_equal 20 , Setting.efgh
95
+ assert_equal 200 , Setting.ijkl
92
96
  end
93
97
 
94
98
  verify 'retains postprocessing after a reload' do
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arsettings
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 1
9
- - 1
10
- version: 1.1.1
8
+ - 2
9
+ version: 1.1.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Joshua Cheek
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-11-16 00:00:00 -06:00
17
+ date: 2010-12-03 00:00:00 -06:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 5
30
28
  segments:
31
29
  - 2
32
30
  - 3
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 49
46
43
  segments:
47
44
  - 0
48
45
  - 8
@@ -58,7 +55,6 @@ dependencies:
58
55
  requirements:
59
56
  - - ~>
60
57
  - !ruby/object:Gem::Version
61
- hash: 25
62
58
  segments:
63
59
  - 1
64
60
  - 3
@@ -84,11 +80,6 @@ files:
84
80
  - examples/on_any_class.rb
85
81
  - test/_helper.rb
86
82
  - test/_in_memory_db.rb
87
- - test/_make_gemsets.sh
88
- - test/_rcov.sh
89
- - test/_reek.sh
90
- - test/_run_all.sh
91
- - test/_run_one.rb
92
83
  - test/activerecord_integration_test.rb
93
84
  - test/arbitrary_class_test.rb
94
85
  - test/packaged_test.rb
@@ -102,6 +93,11 @@ files:
102
93
  - lib/arsettings/settings_class/class_methods.rb
103
94
  - lib/arsettings/settings_class/instance_methods.rb
104
95
  - lib/arsettings.rb
96
+ - script/_make_gemsets.sh
97
+ - script/_rcov.sh
98
+ - script/_reek.sh
99
+ - script/_run_all.sh
100
+ - script/_run_one.rb
105
101
  has_rdoc: true
106
102
  homepage: https://github.com/JoshCheek/ARSettings
107
103
  licenses: []
@@ -117,7 +113,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
113
  requirements:
118
114
  - - ">="
119
115
  - !ruby/object:Gem::Version
120
- hash: 3
121
116
  segments:
122
117
  - 0
123
118
  version: "0"
@@ -126,7 +121,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
121
  requirements:
127
122
  - - ">="
128
123
  - !ruby/object:Gem::Version
129
- hash: 3
130
124
  segments:
131
125
  - 0
132
126
  version: "0"
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- query = File.dirname(__FILE__) << '/*_test.rb'
3
- Dir[query].each { |filename| require filename }