setler 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,10 +34,10 @@ Destroy them:
34
34
  Featureflags.destroy :bacon_dispenser_enabled
35
35
  Settings.destroy :allowed_meats
36
36
 
37
- List all:
37
+ List all settings:
38
38
 
39
- Featureflags.all
40
- Settings.all
39
+ Featureflags.all_settings
40
+ Settings.all_settings
41
41
 
42
42
  Set defaults in an initializer with something like:
43
43
 
@@ -5,3 +5,5 @@ Rachel Heaton github.com/rheaton
5
5
  Corey Innis github.com/coreyti
6
6
  Steven Harman github.com/stevenharman
7
7
  Chris Stefano github.com/virtualstaticvoid
8
+ Brian Stanwyck github.com/brianstanwyck
9
+ Jay Hayes github.com/iamvery
@@ -1,3 +1,5 @@
1
+ require 'rails/version'
2
+
1
3
  module Setler
2
4
  class Settings < ActiveRecord::Base
3
5
  serialize :value
@@ -6,7 +8,14 @@ module Setler
6
8
  cattr_accessor :defaults
7
9
  @@defaults = {}.with_indifferent_access
8
10
 
9
- attr_accessible :var, :value if respond_to?(:attr_accessible)
11
+ if Rails::VERSION::MAJOR == 3
12
+ attr_accessible :var, :value
13
+
14
+ def self.all
15
+ warn '[DEPRECATED] Setler::Settings#all is deprecated. Please use #all_settings'
16
+ all_settings
17
+ end
18
+ end
10
19
 
11
20
  # Get and Set variables when the calling method is the variable name
12
21
  def self.method_missing(method, *args, &block)
@@ -16,6 +25,8 @@ module Setler
16
25
  method_name = method.to_s
17
26
  if method_name.ends_with?("=")
18
27
  self[method_name[0..-2]] = args.first
28
+ elsif method_name.ends_with?("?")
29
+ self[method_name[0..-2]].present?
19
30
  else
20
31
  self[method_name]
21
32
  end
@@ -49,7 +60,7 @@ module Setler
49
60
  end
50
61
  end
51
62
 
52
- def self.all
63
+ def self.all_settings
53
64
  @@defaults.merge(Hash[thing_scoped.all.collect{ |s| [s.var, s.value] }])
54
65
  end
55
66
 
@@ -1,3 +1,3 @@
1
1
  module Setler
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
-
20
+
21
21
  s.add_dependency('activerecord', '>=3.0.0')
22
22
  s.add_dependency('rails', '>=3.0.0')
23
23
 
@@ -32,6 +32,13 @@ class ::SettingsTest < Test::Unit::TestCase
32
32
  assert_equal 'bar', ::Settings.test2
33
33
  end
34
34
 
35
+ def test_get_presence
36
+ ::Settings.truthy = [1,2,3]
37
+ ::Settings.falsy = []
38
+ assert_equal true, ::Settings.truthy?
39
+ assert_equal false, ::Settings.falsy?
40
+ end
41
+
35
42
  def test_get_with_array_syntax
36
43
  assert_equal 'foo', ::Settings["test"]
37
44
  assert_equal 'bar', ::Settings[:test2]
@@ -79,8 +86,8 @@ class ::SettingsTest < Test::Unit::TestCase
79
86
  assert_equal 0.02, ::Settings.float * 2
80
87
  end
81
88
 
82
- def test_all
83
- assert_equal({ "test2" => "bar", "test" => "foo" }, ::Settings.all)
89
+ def test_all_settings
90
+ assert_equal({ "test2" => "bar", "test" => "foo" }, ::Settings.all_settings)
84
91
  end
85
92
 
86
93
  def test_destroy
@@ -114,13 +121,13 @@ class ::SettingsTest < Test::Unit::TestCase
114
121
  def test_user_settings_all
115
122
  ::Settings.destroy_all
116
123
  user = User.create name: 'user 1'
117
- assert_equal ::Preferences.all, user.preferences.all
124
+ assert_equal ::Preferences.all_settings, user.preferences.all_settings
118
125
  user.preferences.likes_bacon = true
119
126
  user.preferences.really_likes_bacon = true
120
- assert user.preferences.all['likes_bacon']
121
- assert !::Settings.all['likes_bacon']
122
- assert user.preferences.all['really_likes_bacon']
123
- assert !::Settings.all['really_likes_bacon']
127
+ assert user.preferences.all_settings['likes_bacon']
128
+ assert !::Settings.all_settings['likes_bacon']
129
+ assert user.preferences.all_settings['really_likes_bacon']
130
+ assert !::Settings.all_settings['really_likes_bacon']
124
131
  end
125
132
 
126
133
  def test_user_settings_override_defaults
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
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: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2013-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: -1206975187554322523
138
+ hash: 153021876405387793
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements:
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  segments:
146
146
  - 0
147
- hash: -1206975187554322523
147
+ hash: 153021876405387793
148
148
  requirements: []
149
149
  rubyforge_project: setler
150
150
  rubygems_version: 1.8.25