user_preferences 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +11 -1
- data/Appraisals +7 -0
- data/CHANGELOG.md +4 -0
- data/README.md +21 -3
- data/gemfiles/rails_4.gemfile +3 -1
- data/gemfiles/rails_5.gemfile +2 -1
- data/gemfiles/rails_6.gemfile +7 -0
- data/lib/user_preferences/preference.rb +1 -1
- data/lib/user_preferences/version.rb +1 -1
- data/spec/migrations/001_create_users.rb +3 -3
- data/spec/migrations/002_create_preferences.rb +3 -3
- data/spec/spec_helper.rb +7 -2
- data/user_preferences.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 45e53fad3262e5c0df4eb853eba0a557ad3ed55fe588f85512f54a5b50ce382c
|
4
|
+
data.tar.gz: 8d4187da04472dc2a57177e80ac57bc1091bf537cebf442913e3907613b1c38b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e18df71224835df0d6dcdd4adf7a17832126388bf5df8d34ee3d08701ed37701851b9b716023463fa22b3865b178a04925450e533b7294538f8a6864e30628a
|
7
|
+
data.tar.gz: 6c94676556bd128a20b6cf05f53817ae883908523b9ec661f1378893c20b345d49ba2a182e6ba2944e7271abca1a011a8f992a52c58fd58c2ba9351cdee5baaa
|
data/.travis.yml
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.
|
4
|
+
- 2.3
|
5
|
+
- 2.4
|
6
|
+
- 2.5
|
7
|
+
- 2.6
|
5
8
|
gemfile:
|
6
9
|
- gemfiles/rails_4.gemfile
|
7
10
|
- gemfiles/rails_5.gemfile
|
11
|
+
- gemfiles/rails_6.gemfile
|
12
|
+
matrix:
|
13
|
+
exclude:
|
14
|
+
- rvm: 2.3
|
15
|
+
gemfile: gemfiles/rails_6.gemfile
|
16
|
+
- rvm: 2.4
|
17
|
+
gemfile: gemfiles/rails_6.gemfile
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -35,9 +35,27 @@ Finally, run the database migrations:
|
|
35
35
|
$ rake db:migrate
|
36
36
|
```
|
37
37
|
|
38
|
+
## Add preferences to your model
|
39
|
+
|
40
|
+
Assuming you have a model called `User`, you can associate it with preferences as
|
41
|
+
follows:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class User < ActiveRecord::Base
|
45
|
+
|
46
|
+
has_preferences
|
47
|
+
|
48
|
+
# the rest of your code ...
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
This declaration takes no arguments, and simply sets up the correct associations
|
53
|
+
along with making available the rest of the methods described in the _API_ section
|
54
|
+
below.
|
55
|
+
|
38
56
|
## Defining preferences
|
39
57
|
|
40
|
-
Your preferences are defined in ``config/user_preferences.yml``. You define each of your
|
58
|
+
Your preferences, along with their default values, are defined in ``config/user_preferences.yml``. You define each of your
|
41
59
|
preferences within a category. This example definition for a binary preference implies that users receive emails notifications by default but not newsletters:
|
42
60
|
```yaml
|
43
61
|
emails:
|
@@ -107,7 +125,7 @@ user.preferences(:emails).reload # => { notifications: 'instant', newsletter: tr
|
|
107
125
|
```ruby
|
108
126
|
newsletter_users = User.with_preference(:email, :newsletter, true) #=> an ActiveRecord::Relation
|
109
127
|
```
|
110
|
-
Note: this _will_ include users who have not
|
128
|
+
Note: this _will_ include users who have not overridden the default value if the value incidentally matches the default value.
|
111
129
|
|
112
130
|
## Other useful stuff
|
113
131
|
|
@@ -134,4 +152,4 @@ $ rake test
|
|
134
152
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
135
153
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
136
154
|
4. Push to the branch (`git push origin my-new-feature`)
|
137
|
-
5. Create new Pull Request
|
155
|
+
5. Create new Pull Request
|
data/gemfiles/rails_4.gemfile
CHANGED
data/gemfiles/rails_5.gemfile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateUsers < ActiveRecord::Migration
|
1
|
+
class CreateUsers < (ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)
|
2
2
|
def self.up
|
3
3
|
create_table :users do |t|
|
4
|
-
t.timestamps
|
4
|
+
t.timestamps null: false
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
9
|
drop_table :users
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreatePreferences < ActiveRecord::Migration
|
1
|
+
class CreatePreferences < (ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)
|
2
2
|
def self.up
|
3
3
|
create_table :preferences do |t|
|
4
4
|
t.integer :user_id, null: false
|
5
5
|
t.string :category, null: false
|
6
6
|
t.string :name, null: false
|
7
7
|
t.integer :value, null: false
|
8
|
-
t.timestamps
|
8
|
+
t.timestamps null: false
|
9
9
|
end
|
10
10
|
|
11
11
|
add_index :preferences, :user_id
|
@@ -16,4 +16,4 @@ class CreatePreferences < ActiveRecord::Migration
|
|
16
16
|
def self.down
|
17
17
|
drop_table :preferences
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,12 @@ require 'active_record/connection_adapters/sqlite3_adapter'
|
|
5
5
|
RSpec.configure do |config|
|
6
6
|
$stdout = StringIO.new # silence migrations
|
7
7
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
8
|
-
ActiveRecord::
|
8
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
9
|
+
ActiveRecord::Migrator.migrations_paths = File.expand_path('../migrations', __FILE__)
|
10
|
+
ActiveRecord::Base.connection.migration_context.migrate
|
11
|
+
else
|
12
|
+
ActiveRecord::Migrator.migrate(File.expand_path('../migrations', __FILE__))
|
13
|
+
end
|
9
14
|
$stdout = STDOUT
|
10
15
|
|
11
16
|
# prevent deprecation warnings
|
@@ -21,4 +26,4 @@ end
|
|
21
26
|
|
22
27
|
class User < ActiveRecord::Base
|
23
28
|
include UserPreferences::HasPreferences
|
24
|
-
end
|
29
|
+
end
|
data/user_preferences.gemspec
CHANGED
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.7"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency 'rspec', '~> 2.14'
|
28
|
-
spec.add_development_dependency 'sqlite3'
|
28
|
+
spec.add_development_dependency 'sqlite3'
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_preferences
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Dust
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
description: "user_preference is a small library for setting and getting categorized
|
98
98
|
user preferences.\n Supports both binary and multivalue preferences
|
99
99
|
and default values. "
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- Rakefile
|
114
114
|
- gemfiles/rails_4.gemfile
|
115
115
|
- gemfiles/rails_5.gemfile
|
116
|
+
- gemfiles/rails_6.gemfile
|
116
117
|
- lib/generators/user_preferences/install_generator.rb
|
117
118
|
- lib/generators/user_preferences/templates/migration.rb
|
118
119
|
- lib/generators/user_preferences/templates/user_preferences.yml
|
@@ -154,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
155
|
- !ruby/object:Gem::Version
|
155
156
|
version: '0'
|
156
157
|
requirements: []
|
157
|
-
|
158
|
-
rubygems_version: 2.4.5.1
|
158
|
+
rubygems_version: 3.0.3
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: User preferences gem for Rails.
|