user_preferences 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 15615015e9ccb0efd6e0db7e176c1d13c8699d71
4
- data.tar.gz: 9d62fe5e9b60512492121e22f93e0fa892ed1344
2
+ SHA256:
3
+ metadata.gz: 45e53fad3262e5c0df4eb853eba0a557ad3ed55fe588f85512f54a5b50ce382c
4
+ data.tar.gz: 8d4187da04472dc2a57177e80ac57bc1091bf537cebf442913e3907613b1c38b
5
5
  SHA512:
6
- metadata.gz: da8293ea1bbfd7cef25c5aa5ca68f77e3789f7e65e04651792f37a0a2e894dbb5c6f99962eaba85689c8be3437169628fc3f1bfd3e900459f6f347845431bb4c
7
- data.tar.gz: e0017a948a1eafaad7e20f80fe9eadcf6d3ec1e81c11f610e661dcc9c011a172aa908bfd8dc0275d00492b190ad61b2fb3913d36b21db2aa3a1cea0c49f8c05d
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.2.6
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
@@ -1,7 +1,14 @@
1
1
  appraise "rails-4" do
2
2
  gem "rails", "~> 4"
3
+ gem "sprockets", "~> 3.7"
4
+ gem "sqlite3", "~> 1.3.6"
3
5
  end
4
6
 
5
7
  appraise "rails-5" do
6
8
  gem "rails", "~> 5.0"
9
+ gem "sprockets", "~> 3.7"
10
+ end
11
+
12
+ appraise "rails-6" do
13
+ gem "rails", "~> 6.0"
7
14
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.1 2019-10-17
4
+ * Fix compatibility with Rails 6
5
+ * Support modern Ruby versions
6
+
3
7
  ## 1.0.0 2017-02-13
4
8
 
5
9
  * Fix compatibility with Rails 5
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 overriden the default value if the value incidentally matches the default value.
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
@@ -3,5 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4"
6
+ gem "sprockets", "~> 3.7"
7
+ gem "sqlite3", "~> 1.3.6"
6
8
 
7
- gemspec :path => "../"
9
+ gemspec path: "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.0"
6
+ gem "sprockets", "~> 3.7"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0"
6
+
7
+ gemspec path: "../"
@@ -8,7 +8,7 @@ class UserPreferences::Preference < ActiveRecord::Base
8
8
  delegate :binary?, :default, :permitted_values, :lookup, :to_db, to: :definition
9
9
 
10
10
  def update_value!(v)
11
- update_attributes!(value: v)
11
+ update!(value: v)
12
12
  end
13
13
 
14
14
  def value
@@ -1,3 +1,3 @@
1
1
  module UserPreferences
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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::Migrator.migrate(File.expand_path('../migrations', __FILE__))
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
@@ -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', '~> 1.3'
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.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: 2017-02-13 00:00:00.000000000 Z
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: '1.3'
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: '1.3'
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
- rubyforge_project:
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.