setler 0.0.10 → 0.0.14

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cbe29674970fc77e130e8ab2927c5afb9697f2f60d0c6b1edd0f7e95c9fa4710
4
+ data.tar.gz: 896867601cf7eee4ae4eeb4cca788952a334f450e9980c123ba38f54568778af
5
+ SHA512:
6
+ metadata.gz: e9f90bc4f78b627a5d512cdf18bdedc7947a80f20fe7ef46acedbdad4f3321e02f76c7d8ab86278c41aee252a9607a2688d31086ee1621123c9ed8e4deec5aef
7
+ data.tar.gz: e01e2a723f9b0db1b77625f5f50912f670edfe71b519f07a975ae07412a360f9d3f7a727fd1b58cc1eb8a9bcc2d04aebf3d44c7c20a12513f046f1d7b6523e20
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ setler
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.8
4
+ - 2.4.7
5
+ - 2.5.7
6
+ - 2.6.5
7
+ before_install: "gem install bundler:1.17.2"
8
+ cache: bundler
9
+ script: "bundle exec rake test"
10
+ notifications:
11
+ email: false
12
+ gemfile:
13
+ - gemfiles/rails_4.gemfile
14
+ - gemfiles/rails_5.gemfile
15
+ - gemfiles/rails_6_edge.gemfile
16
+ matrix:
17
+ fast_finish: true
18
+ exclude:
19
+ - rvm: 2.3.8
20
+ gemfile: gemfiles/rails_6_edge.gemfile
21
+ - rvm: 2.4.7
22
+ gemfile: gemfiles/rails_6_edge.gemfile
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise "rails-4" do
2
+ gem "rails", "4.2.11.1"
3
+ gem 'sqlite3', '1.3.13' # 5/13/2019: LOCKED DOWN AGAIN.
4
+ end
5
+
6
+ appraise "rails-5" do
7
+ gem "rails", "5.2.3"
8
+ gem 'sqlite3'
9
+ end
10
+
11
+ appraise "rails-6-edge" do
12
+ gem 'rails', git: 'https://github.com/rails/rails'
13
+ gem 'sqlite3'
14
+ end
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in setler.gemspec
4
4
  gemspec
data/README.rdoc CHANGED
@@ -2,20 +2,27 @@
2
2
 
3
3
  Setler is a Gem that lets one easily implement the "Feature Flags" pattern, or add settings to individual models. This is a cleanroom implementation of what the 'rails-settings' gem does. It's been forked all over the place, and my favorite version of it doesn't have any tests and doesn't work with settings associated with models.
4
4
 
5
+ {<img src="https://travis-ci.org/ckdake/setler.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/ckdake/setler]
6
+ {<img src="https://badge.fury.io/rb/setler.svg" alt="Gem Version" />}[http://badge.fury.io/rb/setler]
7
+
8
+ While Setler enables you to create both app-level and model-level settings, they are two separate things and don't mix. For example, if you create defaults for the app, they won't appear as defaults for individual models.
9
+
5
10
  == Setup
6
11
 
7
12
  Install the gem by adding this to your Gemfile:
8
13
 
9
14
  gem "setler"
10
-
15
+
11
16
  Generate the model:
12
17
 
13
18
  rails g setler <model_name>
14
-
19
+
15
20
  Run the migration:
16
21
 
17
22
  rake db:migrate
18
-
23
+
24
+ If you are using the `protected_attributes` gem you must add `attr_protected` to the top of you setler model.
25
+
19
26
  == Usage
20
27
 
21
28
  Create/Update settings:
@@ -23,22 +30,22 @@ Create/Update settings:
23
30
  # Method calls and []= are synonymous
24
31
  Featureflags.bacon_dispenser_enabled = true
25
32
  Settings[:allowed_meats] = ['bacon', 'crunchy bacon']
26
-
33
+
27
34
  Read settings:
28
35
 
29
36
  Featureflags.bacon_dispenser_enabled # true
30
37
  Settings[:allowed_meats].include?('bacon') # true
31
-
38
+
32
39
  Destroy them:
33
40
 
34
41
  Featureflags.destroy :bacon_dispenser_enabled
35
42
  Settings.destroy :allowed_meats
36
-
37
- List all:
38
43
 
39
- Featureflags.all
40
- Settings.all
41
-
44
+ List all settings:
45
+
46
+ Featureflags.all_settings
47
+ Settings.all_settings
48
+
42
49
  Set defaults in an initializer with something like:
43
50
 
44
51
  Featureflags.defaults[:bacon_dispenser_enabled] = false
@@ -46,20 +53,20 @@ Set defaults in an initializer with something like:
46
53
 
47
54
  To revert to the default after changing a setting, destroy it.
48
55
  Note: Updating the setting to nil or false no longer makes it the default setting (> 0.0.6), but changes the setting to nil or false.
49
-
56
+
50
57
  Add them to any ActiveRecord object:
51
58
 
52
59
  class User < ActiveRecord::Base
53
- has_setler as: :settings
60
+ has_setler :settings
54
61
  end
55
-
62
+
56
63
  Then you get:
57
-
64
+
58
65
  user = User.first
59
66
  user.settings.favorite_meat = :bacon
60
67
  user.settings.favorite_meat # :bacon
61
68
  user.settings.all # { "favorite_meat" => :bacon }
62
-
69
+
63
70
  TODO: And look em up:
64
71
 
65
72
  User.with_settings_for('favorite_meat') # => scope of users with the favorite_meat setting
@@ -70,8 +77,9 @@ Getting started is pretty straightforward:
70
77
 
71
78
  1. Check out the code: `git clone git://github.com/ckdake/setler.git`
72
79
  2. Bundle install: `bundle install`
73
- 3. Run the tests and make sure they all pass and code coverage is still 100%: `rake test`
74
-
80
+ 3. Run: `appraisal install` to generate the appraisal's gemfiles.
81
+ 4. Run the tests for all supported releases in Appraisals file and make sure they all pass and code coverage is still the same: `appraisal rake test`
82
+
75
83
  If you'd like to contribute code, make your changes and submit a pull request that includes appropriate tests
76
84
 
77
85
  For building the gem: `rake build` and to release a gem to github and Rubygems: `rake release`
data/Rakefile CHANGED
@@ -1,26 +1,33 @@
1
- require 'rake/testtask'
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
2
5
  require 'bundler/gem_tasks'
3
6
 
7
+ require 'rake'
8
+ require 'rake/testtask'
9
+ require 'appraisal'
10
+
4
11
  Rake::TestTask.new(:test) do |test|
5
12
  test.libs << 'lib' << 'test'
6
13
  test.pattern = 'test/**/*_test.rb'
7
14
  test.verbose = true
8
15
  end
9
16
 
10
- task default: [:test]
17
+ require 'bundler/gem_tasks'
11
18
 
12
- namespace :cover_me do
13
- desc "Generates and opens code coverage report."
14
- task :report do
15
- require 'cover_me'
16
- CoverMe.complete!
17
- end
18
- end
19
+ require 'rake'
20
+ require 'appraisal'
19
21
 
20
- task :test do
21
- Rake::Task['cover_me:report'].invoke
22
+ desc 'Default'
23
+ task :default do
24
+ if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
25
+ task default: [:test]
26
+ else
27
+ Rake::Task['appraise'].invoke
28
+ end
22
29
  end
23
30
 
24
- task :spec do
25
- Rake::Task['cover_me:report'].invoke
31
+ task :appraise do
32
+ exec 'appraisal install && appraisal rake test'
26
33
  end
data/contributors.txt CHANGED
@@ -4,3 +4,8 @@ Phil Ostler github.com/philostler
4
4
  Rachel Heaton github.com/rheaton
5
5
  Corey Innis github.com/coreyti
6
6
  Steven Harman github.com/stevenharman
7
+ Chris Stefano github.com/virtualstaticvoid
8
+ Brian Stanwyck github.com/brianstanwyck
9
+ Jay Hayes github.com/iamvery
10
+ Al Snow github.com/jasnow
11
+ Gal Tsubery github.com/tsubery
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.2.11.1"
6
+ gem "sqlite3", "1.3.13"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,128 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ setler (0.0.13)
5
+ activerecord (>= 3.0.0)
6
+ rails (>= 3.0.0)
7
+ sprockets (= 3.7.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (4.2.11.1)
13
+ actionpack (= 4.2.11.1)
14
+ actionview (= 4.2.11.1)
15
+ activejob (= 4.2.11.1)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ actionpack (4.2.11.1)
19
+ actionview (= 4.2.11.1)
20
+ activesupport (= 4.2.11.1)
21
+ rack (~> 1.6)
22
+ rack-test (~> 0.6.2)
23
+ rails-dom-testing (~> 1.0, >= 1.0.5)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
+ actionview (4.2.11.1)
26
+ activesupport (= 4.2.11.1)
27
+ builder (~> 3.1)
28
+ erubis (~> 2.7.0)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
31
+ activejob (4.2.11.1)
32
+ activesupport (= 4.2.11.1)
33
+ globalid (>= 0.3.0)
34
+ activemodel (4.2.11.1)
35
+ activesupport (= 4.2.11.1)
36
+ builder (~> 3.1)
37
+ activerecord (4.2.11.1)
38
+ activemodel (= 4.2.11.1)
39
+ activesupport (= 4.2.11.1)
40
+ arel (~> 6.0)
41
+ activesupport (4.2.11.1)
42
+ i18n (~> 0.7)
43
+ minitest (~> 5.1)
44
+ thread_safe (~> 0.3, >= 0.3.4)
45
+ tzinfo (~> 1.1)
46
+ appraisal (2.2.0)
47
+ bundler
48
+ rake
49
+ thor (>= 0.14.0)
50
+ arel (6.0.4)
51
+ builder (3.2.4)
52
+ concurrent-ruby (1.1.5)
53
+ crass (1.0.6)
54
+ docile (1.3.2)
55
+ erubis (2.7.0)
56
+ globalid (0.4.2)
57
+ activesupport (>= 4.2.0)
58
+ i18n (0.9.5)
59
+ concurrent-ruby (~> 1.0)
60
+ loofah (2.4.0)
61
+ crass (~> 1.0.2)
62
+ nokogiri (>= 1.5.9)
63
+ mail (2.7.1)
64
+ mini_mime (>= 0.1.1)
65
+ mini_mime (1.0.2)
66
+ mini_portile2 (2.4.0)
67
+ minitest (5.14.0)
68
+ nokogiri (1.10.7)
69
+ mini_portile2 (~> 2.4.0)
70
+ rack (1.6.13)
71
+ rack-test (0.6.3)
72
+ rack (>= 1.0)
73
+ rails (4.2.11.1)
74
+ actionmailer (= 4.2.11.1)
75
+ actionpack (= 4.2.11.1)
76
+ actionview (= 4.2.11.1)
77
+ activejob (= 4.2.11.1)
78
+ activemodel (= 4.2.11.1)
79
+ activerecord (= 4.2.11.1)
80
+ activesupport (= 4.2.11.1)
81
+ bundler (>= 1.3.0, < 2.0)
82
+ railties (= 4.2.11.1)
83
+ sprockets-rails
84
+ rails-deprecated_sanitizer (1.0.3)
85
+ activesupport (>= 4.2.0.alpha)
86
+ rails-dom-testing (1.0.9)
87
+ activesupport (>= 4.2.0, < 5.0)
88
+ nokogiri (~> 1.6)
89
+ rails-deprecated_sanitizer (>= 1.0.1)
90
+ rails-html-sanitizer (1.3.0)
91
+ loofah (~> 2.3)
92
+ railties (4.2.11.1)
93
+ actionpack (= 4.2.11.1)
94
+ activesupport (= 4.2.11.1)
95
+ rake (>= 0.8.7)
96
+ thor (>= 0.18.1, < 2.0)
97
+ rake (13.0.1)
98
+ simplecov (0.18.1)
99
+ docile (~> 1.1)
100
+ simplecov-html (~> 0.11.0)
101
+ simplecov-html (0.11.0)
102
+ sprockets (3.7.2)
103
+ concurrent-ruby (~> 1.0)
104
+ rack (> 1, < 3)
105
+ sprockets-rails (3.2.1)
106
+ actionpack (>= 4.0)
107
+ activesupport (>= 4.0)
108
+ sprockets (>= 3.0.0)
109
+ sqlite3 (1.3.13)
110
+ thor (1.0.1)
111
+ thread_safe (0.3.6)
112
+ tzinfo (1.2.6)
113
+ thread_safe (~> 0.1)
114
+
115
+ PLATFORMS
116
+ ruby
117
+
118
+ DEPENDENCIES
119
+ appraisal
120
+ minitest
121
+ rails (= 4.2.11.1)
122
+ rake
123
+ setler!
124
+ simplecov
125
+ sqlite3 (= 1.3.13)
126
+
127
+ BUNDLED WITH
128
+ 1.17.3
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "5.2.3"
6
+ gem "sqlite3"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,143 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ setler (0.0.13)
5
+ activerecord (>= 3.0.0)
6
+ rails (>= 3.0.0)
7
+ sprockets (= 3.7.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (5.2.3)
13
+ actionpack (= 5.2.3)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailer (5.2.3)
17
+ actionpack (= 5.2.3)
18
+ actionview (= 5.2.3)
19
+ activejob (= 5.2.3)
20
+ mail (~> 2.5, >= 2.5.4)
21
+ rails-dom-testing (~> 2.0)
22
+ actionpack (5.2.3)
23
+ actionview (= 5.2.3)
24
+ activesupport (= 5.2.3)
25
+ rack (~> 2.0)
26
+ rack-test (>= 0.6.3)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ actionview (5.2.3)
30
+ activesupport (= 5.2.3)
31
+ builder (~> 3.1)
32
+ erubi (~> 1.4)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
+ activejob (5.2.3)
36
+ activesupport (= 5.2.3)
37
+ globalid (>= 0.3.6)
38
+ activemodel (5.2.3)
39
+ activesupport (= 5.2.3)
40
+ activerecord (5.2.3)
41
+ activemodel (= 5.2.3)
42
+ activesupport (= 5.2.3)
43
+ arel (>= 9.0)
44
+ activestorage (5.2.3)
45
+ actionpack (= 5.2.3)
46
+ activerecord (= 5.2.3)
47
+ marcel (~> 0.3.1)
48
+ activesupport (5.2.3)
49
+ concurrent-ruby (~> 1.0, >= 1.0.2)
50
+ i18n (>= 0.7, < 2)
51
+ minitest (~> 5.1)
52
+ tzinfo (~> 1.1)
53
+ appraisal (2.2.0)
54
+ bundler
55
+ rake
56
+ thor (>= 0.14.0)
57
+ arel (9.0.0)
58
+ builder (3.2.4)
59
+ concurrent-ruby (1.1.5)
60
+ crass (1.0.6)
61
+ docile (1.3.2)
62
+ erubi (1.9.0)
63
+ globalid (0.4.2)
64
+ activesupport (>= 4.2.0)
65
+ i18n (1.8.2)
66
+ concurrent-ruby (~> 1.0)
67
+ loofah (2.4.0)
68
+ crass (~> 1.0.2)
69
+ nokogiri (>= 1.5.9)
70
+ mail (2.7.1)
71
+ mini_mime (>= 0.1.1)
72
+ marcel (0.3.3)
73
+ mimemagic (~> 0.3.2)
74
+ method_source (0.9.2)
75
+ mimemagic (0.3.4)
76
+ mini_mime (1.0.2)
77
+ mini_portile2 (2.4.0)
78
+ minitest (5.14.0)
79
+ nio4r (2.5.2)
80
+ nokogiri (1.10.7)
81
+ mini_portile2 (~> 2.4.0)
82
+ rack (2.2.1)
83
+ rack-test (1.1.0)
84
+ rack (>= 1.0, < 3)
85
+ rails (5.2.3)
86
+ actioncable (= 5.2.3)
87
+ actionmailer (= 5.2.3)
88
+ actionpack (= 5.2.3)
89
+ actionview (= 5.2.3)
90
+ activejob (= 5.2.3)
91
+ activemodel (= 5.2.3)
92
+ activerecord (= 5.2.3)
93
+ activestorage (= 5.2.3)
94
+ activesupport (= 5.2.3)
95
+ bundler (>= 1.3.0)
96
+ railties (= 5.2.3)
97
+ sprockets-rails (>= 2.0.0)
98
+ rails-dom-testing (2.0.3)
99
+ activesupport (>= 4.2.0)
100
+ nokogiri (>= 1.6)
101
+ rails-html-sanitizer (1.3.0)
102
+ loofah (~> 2.3)
103
+ railties (5.2.3)
104
+ actionpack (= 5.2.3)
105
+ activesupport (= 5.2.3)
106
+ method_source
107
+ rake (>= 0.8.7)
108
+ thor (>= 0.19.0, < 2.0)
109
+ rake (13.0.1)
110
+ simplecov (0.18.1)
111
+ docile (~> 1.1)
112
+ simplecov-html (~> 0.11.0)
113
+ simplecov-html (0.11.0)
114
+ sprockets (3.7.2)
115
+ concurrent-ruby (~> 1.0)
116
+ rack (> 1, < 3)
117
+ sprockets-rails (3.2.1)
118
+ actionpack (>= 4.0)
119
+ activesupport (>= 4.0)
120
+ sprockets (>= 3.0.0)
121
+ sqlite3 (1.4.2)
122
+ thor (1.0.1)
123
+ thread_safe (0.3.6)
124
+ tzinfo (1.2.6)
125
+ thread_safe (~> 0.1)
126
+ websocket-driver (0.7.1)
127
+ websocket-extensions (>= 0.1.0)
128
+ websocket-extensions (0.1.4)
129
+
130
+ PLATFORMS
131
+ ruby
132
+
133
+ DEPENDENCIES
134
+ appraisal
135
+ minitest
136
+ rails (= 5.2.3)
137
+ rake
138
+ setler!
139
+ simplecov
140
+ sqlite3
141
+
142
+ BUNDLED WITH
143
+ 1.17.3
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", git: "https://github.com/rails/rails"
6
+ gem "sqlite3"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,167 @@
1
+ GIT
2
+ remote: https://github.com/rails/rails
3
+ revision: c77a949299fcddd0f6f35d9bc21888b862ff665c
4
+ specs:
5
+ actioncable (6.1.0.alpha)
6
+ actionpack (= 6.1.0.alpha)
7
+ activesupport (= 6.1.0.alpha)
8
+ nio4r (~> 2.0)
9
+ websocket-driver (>= 0.6.1)
10
+ actionmailbox (6.1.0.alpha)
11
+ actionpack (= 6.1.0.alpha)
12
+ activejob (= 6.1.0.alpha)
13
+ activerecord (= 6.1.0.alpha)
14
+ activestorage (= 6.1.0.alpha)
15
+ activesupport (= 6.1.0.alpha)
16
+ mail (>= 2.7.1)
17
+ actionmailer (6.1.0.alpha)
18
+ actionpack (= 6.1.0.alpha)
19
+ actionview (= 6.1.0.alpha)
20
+ activejob (= 6.1.0.alpha)
21
+ activesupport (= 6.1.0.alpha)
22
+ mail (~> 2.5, >= 2.5.4)
23
+ rails-dom-testing (~> 2.0)
24
+ actionpack (6.1.0.alpha)
25
+ actionview (= 6.1.0.alpha)
26
+ activesupport (= 6.1.0.alpha)
27
+ rack (~> 2.0, >= 2.0.8)
28
+ rack-test (>= 0.6.3)
29
+ rails-dom-testing (~> 2.0)
30
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
31
+ actiontext (6.1.0.alpha)
32
+ actionpack (= 6.1.0.alpha)
33
+ activerecord (= 6.1.0.alpha)
34
+ activestorage (= 6.1.0.alpha)
35
+ activesupport (= 6.1.0.alpha)
36
+ nokogiri (>= 1.8.5)
37
+ actionview (6.1.0.alpha)
38
+ activesupport (= 6.1.0.alpha)
39
+ builder (~> 3.1)
40
+ erubi (~> 1.4)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
43
+ activejob (6.1.0.alpha)
44
+ activesupport (= 6.1.0.alpha)
45
+ globalid (>= 0.3.6)
46
+ activemodel (6.1.0.alpha)
47
+ activesupport (= 6.1.0.alpha)
48
+ activerecord (6.1.0.alpha)
49
+ activemodel (= 6.1.0.alpha)
50
+ activesupport (= 6.1.0.alpha)
51
+ activestorage (6.1.0.alpha)
52
+ actionpack (= 6.1.0.alpha)
53
+ activejob (= 6.1.0.alpha)
54
+ activerecord (= 6.1.0.alpha)
55
+ activesupport (= 6.1.0.alpha)
56
+ marcel (~> 0.3.1)
57
+ activesupport (6.1.0.alpha)
58
+ concurrent-ruby (~> 1.0, >= 1.0.2)
59
+ i18n (>= 1.6, < 2)
60
+ minitest (~> 5.1)
61
+ tzinfo (~> 1.1)
62
+ zeitwerk (~> 2.2, >= 2.2.2)
63
+ rails (6.1.0.alpha)
64
+ actioncable (= 6.1.0.alpha)
65
+ actionmailbox (= 6.1.0.alpha)
66
+ actionmailer (= 6.1.0.alpha)
67
+ actionpack (= 6.1.0.alpha)
68
+ actiontext (= 6.1.0.alpha)
69
+ actionview (= 6.1.0.alpha)
70
+ activejob (= 6.1.0.alpha)
71
+ activemodel (= 6.1.0.alpha)
72
+ activerecord (= 6.1.0.alpha)
73
+ activestorage (= 6.1.0.alpha)
74
+ activesupport (= 6.1.0.alpha)
75
+ bundler (>= 1.3.0)
76
+ railties (= 6.1.0.alpha)
77
+ sprockets-rails (>= 2.0.0)
78
+ railties (6.1.0.alpha)
79
+ actionpack (= 6.1.0.alpha)
80
+ activesupport (= 6.1.0.alpha)
81
+ method_source
82
+ rake (>= 0.8.7)
83
+ thor (~> 1.0)
84
+
85
+ PATH
86
+ remote: ..
87
+ specs:
88
+ setler (0.0.13)
89
+ activerecord (>= 3.0.0)
90
+ rails (>= 3.0.0)
91
+ sprockets (= 3.7.2)
92
+
93
+ GEM
94
+ remote: https://rubygems.org/
95
+ specs:
96
+ appraisal (2.2.0)
97
+ bundler
98
+ rake
99
+ thor (>= 0.14.0)
100
+ builder (3.2.4)
101
+ concurrent-ruby (1.1.5)
102
+ crass (1.0.6)
103
+ docile (1.3.2)
104
+ erubi (1.9.0)
105
+ globalid (0.4.2)
106
+ activesupport (>= 4.2.0)
107
+ i18n (1.8.2)
108
+ concurrent-ruby (~> 1.0)
109
+ loofah (2.4.0)
110
+ crass (~> 1.0.2)
111
+ nokogiri (>= 1.5.9)
112
+ mail (2.7.1)
113
+ mini_mime (>= 0.1.1)
114
+ marcel (0.3.3)
115
+ mimemagic (~> 0.3.2)
116
+ method_source (0.9.2)
117
+ mimemagic (0.3.4)
118
+ mini_mime (1.0.2)
119
+ mini_portile2 (2.4.0)
120
+ minitest (5.14.0)
121
+ nio4r (2.5.2)
122
+ nokogiri (1.10.7)
123
+ mini_portile2 (~> 2.4.0)
124
+ rack (2.2.1)
125
+ rack-test (1.1.0)
126
+ rack (>= 1.0, < 3)
127
+ rails-dom-testing (2.0.3)
128
+ activesupport (>= 4.2.0)
129
+ nokogiri (>= 1.6)
130
+ rails-html-sanitizer (1.3.0)
131
+ loofah (~> 2.3)
132
+ rake (13.0.1)
133
+ simplecov (0.18.1)
134
+ docile (~> 1.1)
135
+ simplecov-html (~> 0.11.0)
136
+ simplecov-html (0.11.0)
137
+ sprockets (3.7.2)
138
+ concurrent-ruby (~> 1.0)
139
+ rack (> 1, < 3)
140
+ sprockets-rails (3.2.1)
141
+ actionpack (>= 4.0)
142
+ activesupport (>= 4.0)
143
+ sprockets (>= 3.0.0)
144
+ sqlite3 (1.4.2)
145
+ thor (1.0.1)
146
+ thread_safe (0.3.6)
147
+ tzinfo (1.2.6)
148
+ thread_safe (~> 0.1)
149
+ websocket-driver (0.7.1)
150
+ websocket-extensions (>= 0.1.0)
151
+ websocket-extensions (0.1.4)
152
+ zeitwerk (2.2.2)
153
+
154
+ PLATFORMS
155
+ ruby
156
+
157
+ DEPENDENCIES
158
+ appraisal
159
+ minitest
160
+ rails!
161
+ rake
162
+ setler!
163
+ simplecov
164
+ sqlite3
165
+
166
+ BUNDLED WITH
167
+ 1.17.3
@@ -9,6 +9,7 @@ class SetlerCreate<%= table_name.camelize %> < ActiveRecord::Migration
9
9
  end
10
10
 
11
11
  add_index :<%= table_name %>, [ :thing_type, :thing_id, :var ], unique: true
12
+ add_index :<%= table_name %>, :var, unique: true, where: "thing_id IS NULL AND thing_type is NULL"
12
13
  end
13
14
 
14
15
  def self.down
@@ -2,6 +2,7 @@ module Setler
2
2
  class ScopedSettings < Settings
3
3
  def self.for_thing(object, scopename)
4
4
  self.table_name = scopename
5
+ self.defaults = settings_constantize(scopename).defaults
5
6
  @object = object
6
7
  self
7
8
  end
@@ -10,5 +11,11 @@ module Setler
10
11
  self.base_class.where(thing_type: @object.class.base_class.to_s, thing_id: @object.id)
11
12
  end
12
13
 
14
+ # do not use rails default to singularize because setler examples
15
+ # user plural class names
16
+ def self.settings_constantize(scopename)
17
+ Object.const_get(scopename.to_s.camelize)
18
+ end
19
+
13
20
  end
14
21
  end
@@ -1,10 +1,26 @@
1
+ require 'rails/version'
2
+
1
3
  module Setler
2
4
  class Settings < ActiveRecord::Base
3
5
  serialize :value
4
6
  self.abstract_class = true
5
7
 
6
- cattr_accessor :defaults
7
- @@defaults = {}.with_indifferent_access
8
+ def self.defaults
9
+ @defaults ||= {}.with_indifferent_access
10
+ end
11
+
12
+ def self.defaults=(defaults)
13
+ @defaults = defaults.with_indifferent_access
14
+ end
15
+
16
+ if Rails::VERSION::MAJOR == 3
17
+ attr_accessible :var, :value
18
+
19
+ def self.all
20
+ warn '[DEPRECATED] Setler::Settings#all is deprecated. Please use #all_settings'
21
+ all_settings
22
+ end
23
+ end
8
24
 
9
25
  # Get and Set variables when the calling method is the variable name
10
26
  def self.method_missing(method, *args, &block)
@@ -14,6 +30,8 @@ module Setler
14
30
  method_name = method.to_s
15
31
  if method_name.ends_with?("=")
16
32
  self[method_name[0..-2]] = args.first
33
+ elsif method_name.ends_with?("?")
34
+ self[method_name[0..-2]].present?
17
35
  else
18
36
  self[method_name]
19
37
  end
@@ -22,7 +40,7 @@ module Setler
22
40
 
23
41
  def self.[](var)
24
42
  the_setting = thing_scoped.find_by_var(var.to_s)
25
- the_setting.present? ? the_setting.value : @@defaults[var]
43
+ the_setting.present? ? the_setting.value : defaults[var]
26
44
  end
27
45
 
28
46
  def self.[]=(var, value)
@@ -30,11 +48,19 @@ module Setler
30
48
  # thing_scoped.find_or_create_by_var(method_name[0..-2]) should work but doesnt for some reason
31
49
  # When @object is present, thing_scoped sets the where scope for the polymorphic association
32
50
  # but the find_or_create_by wasn't using the thing_type and thing_id
33
- thing_scoped.find_or_create_by_var_and_thing_type_and_thing_id(
34
- var.to_s,
35
- @object.try(:class).try(:base_class).try(:to_s),
36
- @object.try(:id)
37
- ).update_attributes({ :value => value })
51
+ if Rails::VERSION::MAJOR == 3
52
+ thing_scoped.find_or_create_by_var_and_thing_type_and_thing_id(
53
+ var.to_s,
54
+ @object.try(:class).try(:base_class).try(:to_s),
55
+ @object.try(:id)
56
+ ).update({ :value => value })
57
+ else
58
+ thing_scoped.find_or_create_by(
59
+ var: var.to_s,
60
+ thing_type: @object.try(:class).try(:base_class).try(:to_s),
61
+ thing_id: @object.try(:id)
62
+ ).update({ :value => value })
63
+ end
38
64
  end
39
65
 
40
66
  def self.destroy(var_name)
@@ -47,8 +73,8 @@ module Setler
47
73
  end
48
74
  end
49
75
 
50
- def self.all
51
- @@defaults.merge(Hash[thing_scoped.all.collect{ |s| [s.var, s.value] }])
76
+ def self.all_settings
77
+ defaults.merge(Hash[thing_scoped.all.collect{ |s| [s.var, s.value] }])
52
78
  end
53
79
 
54
80
  def self.thing_scoped
@@ -1,3 +1,3 @@
1
1
  module Setler
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.14"
3
3
  end
data/setler.gemspec CHANGED
@@ -7,21 +7,22 @@ Gem::Specification.new do |s|
7
7
  s.version = Setler::VERSION
8
8
  s.authors = ["Chris Kelly"]
9
9
  s.email = ["ckdake@ckdake.com"]
10
+ s.license = 'MIT'
10
11
  s.homepage = "https://github.com/ckdake/setler"
11
12
  s.summary = %q{Settler lets you use the 'Feature Flags' pettern or add settings to models.}
12
13
  s.description = %q{Setler is a Gem that lets one easily implement the "Feature Flags" pattern, or add settings to individual models. This is a cleanroom implementation of what the 'rails-settings' gem does. It's been forked all over the place, and my favorite version of it doesn't have any tests and doesn't work with settings associated with models.}
13
14
 
14
- s.rubyforge_project = "setler"
15
-
16
15
  s.files = `git ls-files`.split("\n")
17
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
18
  s.require_paths = ["lib"]
20
-
19
+
21
20
  s.add_dependency('activerecord', '>=3.0.0')
22
21
  s.add_dependency('rails', '>=3.0.0')
22
+ s.add_dependency('sprockets', '3.7.2') # 10/16/2019: LOCKED DOWN
23
23
 
24
- s.add_development_dependency('sqlite3')
25
24
  s.add_development_dependency('rake')
26
- s.add_development_dependency('cover_me')
25
+ s.add_development_dependency('minitest')
26
+ s.add_development_dependency('simplecov')
27
+ s.add_development_dependency('appraisal')
27
28
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ::SettingsTest < Test::Unit::TestCase
3
+ class ::SettingsTest < Minitest::Test
4
4
  setup_db
5
5
 
6
6
  def setup
@@ -10,7 +10,10 @@ class ::SettingsTest < Test::Unit::TestCase
10
10
 
11
11
  def teardown
12
12
  ::Settings.delete_all
13
+ ::Settings.defaults = {}.with_indifferent_access
14
+
13
15
  ::Preferences.delete_all
16
+ ::Preferences.defaults = {}.with_indifferent_access
14
17
  end
15
18
 
16
19
  def test_defaults
@@ -32,6 +35,13 @@ class ::SettingsTest < Test::Unit::TestCase
32
35
  assert_equal 'bar', ::Settings.test2
33
36
  end
34
37
 
38
+ def test_get_presence
39
+ ::Settings.truthy = [1,2,3]
40
+ ::Settings.falsy = []
41
+ assert_equal true, ::Settings.truthy?
42
+ assert_equal false, ::Settings.falsy?
43
+ end
44
+
35
45
  def test_get_with_array_syntax
36
46
  assert_equal 'foo', ::Settings["test"]
37
47
  assert_equal 'bar', ::Settings[:test2]
@@ -50,7 +60,7 @@ class ::SettingsTest < Test::Unit::TestCase
50
60
  def test_update_with_nil_and_default_not_nil
51
61
  ::Settings.defaults[:foo] = :test
52
62
  ::Settings.foo = nil
53
- assert_equal nil, ::Settings.foo
63
+ assert_nil ::Settings.foo
54
64
  end
55
65
 
56
66
  def test_update_with_array_syntax
@@ -66,8 +76,20 @@ class ::SettingsTest < Test::Unit::TestCase
66
76
  assert_equal '123', ::Settings.onetwothree
67
77
  end
68
78
 
79
+ def test_multithreaded_create
80
+ s1 = Settings.new var: :conflict, value: 1
81
+ s2 = Settings.new var: :conflict, value: 2
82
+ s1.save!
83
+ exc = assert_raises ActiveRecord::RecordNotUnique, ActiveRecord::StatementInvalid do
84
+ s2.save!
85
+ end
86
+ unless exc.is_a?(ActiveRecord::RecordNotUnique)
87
+ assert exc.message.match(/UNIQUE/)
88
+ end
89
+ end
90
+
69
91
  def test_complex_serialization
70
- complex = [1, '2', {:three => true}]
92
+ complex = [1, '2', {"three" => true}]
71
93
  ::Settings.complex = complex
72
94
  assert_equal complex, ::Settings.complex
73
95
  end
@@ -79,12 +101,12 @@ class ::SettingsTest < Test::Unit::TestCase
79
101
  assert_equal 0.02, ::Settings.float * 2
80
102
  end
81
103
 
82
- def test_all
83
- assert_equal({ "test2" => "bar", "test" => "foo" }, ::Settings.all)
104
+ def test_all_settings
105
+ assert_equal({ "test2" => "bar", "test" => "foo" }, ::Settings.all_settings)
84
106
  end
85
107
 
86
108
  def test_destroy
87
- assert_not_nil ::Settings.test
109
+ refute_nil ::Settings.test
88
110
  ::Settings.destroy :test
89
111
  assert_nil ::Settings.test
90
112
  end
@@ -114,13 +136,13 @@ class ::SettingsTest < Test::Unit::TestCase
114
136
  def test_user_settings_all
115
137
  ::Settings.destroy_all
116
138
  user = User.create name: 'user 1'
117
- assert_equal ::Preferences.all, user.preferences.all
139
+ assert_equal ::Preferences.all_settings, user.preferences.all_settings
118
140
  user.preferences.likes_bacon = true
119
141
  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']
142
+ assert user.preferences.all_settings['likes_bacon']
143
+ assert !::Settings.all_settings['likes_bacon']
144
+ assert user.preferences.all_settings['really_likes_bacon']
145
+ assert !::Settings.all_settings['really_likes_bacon']
124
146
  end
125
147
 
126
148
  def test_user_settings_override_defaults
@@ -148,7 +170,7 @@ class ::SettingsTest < Test::Unit::TestCase
148
170
  # end
149
171
 
150
172
  def test_destroy_when_setting_does_not_exist
151
- assert_raise Setler::SettingNotFound do
173
+ assert_raises Setler::SettingNotFound do
152
174
  ::Settings.destroy :not_a_setting
153
175
  end
154
176
  end
@@ -157,11 +179,17 @@ class ::SettingsTest < Test::Unit::TestCase
157
179
  ::Preferences.create var: 'test', value: 'preferences foo'
158
180
  ::Preferences.create var: 'test2', value: 'preferences bar'
159
181
 
160
- assert_not_equal ::Settings.defaults, ::Preferences.defaults
182
+ refute_match ::Settings.all_settings, ::Preferences.all_settings
161
183
 
162
184
  assert_equal 'foo', ::Settings[:test]
163
185
  assert_equal 'bar', ::Settings[:test2]
164
186
  assert_equal 'preferences foo', ::Preferences[:test]
165
187
  assert_equal 'preferences bar', ::Preferences[:test2]
166
188
  end
189
+
190
+ def test_defaults_are_independent
191
+ ::Settings.defaults[:foo] = false
192
+
193
+ refute_equal ::Settings.defaults, ::Preferences.defaults
194
+ end
167
195
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
- require 'cover_me'
2
1
  require 'rubygems'
3
2
 
3
+ require 'simplecov'
4
+ SimpleCov.start 'rails'
5
+
4
6
  require 'bundler'
5
7
  begin
6
8
  Bundler.setup(:default, :development)
@@ -10,8 +12,9 @@ rescue Bundler::BundlerError => e
10
12
  exit e.status_code
11
13
  end
12
14
 
15
+ require 'rails'
13
16
  require 'active_record'
14
- require 'test/unit'
17
+ require 'minitest/autorun'
15
18
 
16
19
  require_relative '../lib/setler'
17
20
 
@@ -34,18 +37,20 @@ def setup_db
34
37
  t.text :value, :null => true
35
38
  t.integer :thing_id, :null => true
36
39
  t.string :thing_type, :limit => 30, :null => true
37
- t.timestamps
40
+ t.timestamps null: false
38
41
  end
39
42
  add_index :settings, [ :thing_type, :thing_id, :var ], :unique => true
43
+ add_index :settings, :var, unique: true, where: "thing_id IS NULL AND thing_type is NULL"
40
44
 
41
45
  create_table :preferences do |t|
42
46
  t.string :var, :null => false
43
47
  t.text :value, :null => true
44
48
  t.integer :thing_id, :null => true
45
49
  t.string :thing_type, :limit => 30, :null => true
46
- t.timestamps
50
+ t.timestamps null: false
47
51
  end
48
52
  add_index :preferences, [ :thing_type, :thing_id, :var ], :unique => true
53
+ add_index :preferences, :var, unique: true, where: "thing_id IS NULL AND thing_type is NULL"
49
54
 
50
55
  create_table :users do |t|
51
56
  t.string :name
metadata CHANGED
@@ -1,94 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
5
- prerelease:
4
+ version: 0.0.14
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chris Kelly
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-31 00:00:00.000000000 Z
11
+ date: 2021-11-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rails
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 3.0.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 3.0.0
46
41
  - !ruby/object:Gem::Dependency
47
- name: sqlite3
42
+ name: sprockets
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.7.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.7.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - ">="
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  - !ruby/object:Gem::Dependency
63
- name: rake
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
64
85
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
86
  requirements:
67
- - - ! '>='
87
+ - - ">="
68
88
  - !ruby/object:Gem::Version
69
89
  version: '0'
70
90
  type: :development
71
91
  prerelease: false
72
92
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
93
  requirements:
75
- - - ! '>='
94
+ - - ">="
76
95
  - !ruby/object:Gem::Version
77
96
  version: '0'
78
97
  - !ruby/object:Gem::Dependency
79
- name: cover_me
98
+ name: appraisal
80
99
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
100
  requirements:
83
- - - ! '>='
101
+ - - ">="
84
102
  - !ruby/object:Gem::Version
85
103
  version: '0'
86
104
  type: :development
87
105
  prerelease: false
88
106
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
107
  requirements:
91
- - - ! '>='
108
+ - - ">="
92
109
  - !ruby/object:Gem::Version
93
110
  version: '0'
94
111
  description: Setler is a Gem that lets one easily implement the "Feature Flags" pattern,
@@ -102,13 +119,22 @@ executables: []
102
119
  extensions: []
103
120
  extra_rdoc_files: []
104
121
  files:
105
- - .gitignore
106
- - .rvmrc
122
+ - ".gitignore"
123
+ - ".ruby-gemset"
124
+ - ".ruby-version"
125
+ - ".travis.yml"
126
+ - Appraisals
107
127
  - Gemfile
108
128
  - MIT-LICENSE
109
129
  - README.rdoc
110
130
  - Rakefile
111
131
  - contributors.txt
132
+ - gemfiles/rails_4.gemfile
133
+ - gemfiles/rails_4.gemfile.lock
134
+ - gemfiles/rails_5.gemfile
135
+ - gemfiles/rails_5.gemfile.lock
136
+ - gemfiles/rails_6_edge.gemfile
137
+ - gemfiles/rails_6_edge.gemfile.lock
112
138
  - lib/generators/setler/setler_generator.rb
113
139
  - lib/generators/setler/templates/migration.rb
114
140
  - lib/generators/setler/templates/model.rb
@@ -122,28 +148,27 @@ files:
122
148
  - test/settings_test.rb
123
149
  - test/test_helper.rb
124
150
  homepage: https://github.com/ckdake/setler
125
- licenses: []
126
- post_install_message:
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
127
155
  rdoc_options: []
128
156
  require_paths:
129
157
  - lib
130
158
  required_ruby_version: !ruby/object:Gem::Requirement
131
- none: false
132
159
  requirements:
133
- - - ! '>='
160
+ - - ">="
134
161
  - !ruby/object:Gem::Version
135
162
  version: '0'
136
163
  required_rubygems_version: !ruby/object:Gem::Requirement
137
- none: false
138
164
  requirements:
139
- - - ! '>='
165
+ - - ">="
140
166
  - !ruby/object:Gem::Version
141
167
  version: '0'
142
168
  requirements: []
143
- rubyforge_project: setler
144
- rubygems_version: 1.8.24
145
- signing_key:
146
- specification_version: 3
169
+ rubygems_version: 3.2.22
170
+ signing_key:
171
+ specification_version: 4
147
172
  summary: Settler lets you use the 'Feature Flags' pettern or add settings to models.
148
173
  test_files:
149
174
  - test/settings_test.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm 1.9.2@setler