username 1.1.0 → 2.0.0

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
2
  SHA256:
3
- metadata.gz: a76b0ea615f4def3a94b66ca1a024202c36bf106c9261ff20cfee0a95e051cfa
4
- data.tar.gz: 809f5283ee7f6b15a56e99802afa6767c1513c378072afa032dc21d171706882
3
+ metadata.gz: c8de930561c5caa99fd5429ef17fb6699a6090e07d27fdd190572d22bc2d4608
4
+ data.tar.gz: 4fab1cb6940a149fca8226ab472cd0a56ac4686d05a42d88bbdecf8d5141a7ae
5
5
  SHA512:
6
- metadata.gz: 8bebd2607b4a0b2bf24dfb973524799ca074bce7424113a1d98b1bb78667da6c149f440968801b7fd0fd273242b30330883f87bd483b140cc6669049df63220f
7
- data.tar.gz: 15456eb519fbe2062ebb7cab85f063774f9f9e4e6e3535a5fd01cf45744a621aea1048e4c6fa2926e0bb49e5cbd4a0deba17ee949e6ab052c9a4e56c1e4e8348
6
+ metadata.gz: 793a84c0d5d2d0ecd794700940576bbfd5de43fcba5f01d01c66985df217218c14328503d3cd94422056eb696a6064998c6598e8fe34d3cea05b3d5620ceca43
7
+ data.tar.gz: cf50fc8fca114cc98651806e8d9b2b28596c500a914a3bc8a78569b0d736a5f9ba43344c4cd017b1c5d40d970818df000537f1194b0d464f838a5303f87b4871
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  * nothing yet
6
6
 
7
+ ### 2.0.0 - 2018/05/24
8
+
9
+ * features
10
+ * add functionality directly by including concerns
11
+
7
12
  ### 1.1.0 - 2018/01/24
8
13
 
9
14
  * features
data/README.md CHANGED
@@ -55,7 +55,7 @@ You can add usernames to an ActiveRecord model:
55
55
 
56
56
  ```ruby
57
57
  class User < ApplicationRecord
58
- has_username
58
+ include Username::Model
59
59
  end
60
60
  ```
61
61
 
@@ -81,7 +81,8 @@ If you are using Devise and you want to allow your users to sign in using either
81
81
 
82
82
  ```ruby
83
83
  class User < ApplicationRecord
84
- has_username devise: true
84
+ include Username::Model
85
+ include Username::Model::Devise
85
86
  end
86
87
  ```
87
88
 
@@ -3,22 +3,12 @@ module Username
3
3
 
4
4
  extend ActiveSupport::Concern
5
5
 
6
- module ClassMethods
7
- def has_username options = {}
8
- defaults = {
9
- devise: false
10
- }
11
- options = defaults.merge options
12
-
13
- Username.configuration&.models << self.name
14
- validate :username_validation
15
-
16
- if options[:devise]
17
- attr_accessor :login
18
- extend Username::Model::DeviseMethods
19
- end
20
- end
6
+ included do
7
+ Username.configuration&.models << self.name
8
+ validate :username_validation
9
+ end
21
10
 
11
+ module ClassMethods
22
12
  def username_valid? username
23
13
  unless username.nil?
24
14
  valid = true
@@ -37,17 +27,6 @@ module Username
37
27
  end
38
28
  end
39
29
 
40
- module DeviseMethods
41
- def find_for_database_authentication warden_conditions
42
- conditions = warden_conditions.dup
43
- if login = conditions.delete(:login)
44
- where(conditions.to_h).where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase }]).first
45
- elsif conditions.has_key?(:username) || conditions.has_key?(:email)
46
- where(conditions.to_h).first
47
- end
48
- end
49
- end
50
-
51
30
  def username_available? username
52
31
  unless username.nil?
53
32
  valid = true
@@ -0,0 +1,24 @@
1
+ module Username
2
+ module Model
3
+ module Devise
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_accessor :login
9
+ end
10
+
11
+ module ClassMethods
12
+ def find_for_database_authentication warden_conditions
13
+ conditions = warden_conditions.dup
14
+ if login = conditions.delete(:login)
15
+ where(conditions.to_h).where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase }]).first
16
+ elsif conditions.has_key?(:username) || conditions.has_key?(:email)
17
+ where(conditions.to_h).first
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
data/lib/username.rb CHANGED
@@ -5,6 +5,5 @@ module Username
5
5
  require 'username/configuration'
6
6
 
7
7
  require 'username/engine'
8
- require 'username/railtie'
9
8
 
10
9
  end
@@ -1,5 +1,5 @@
1
1
  module Username
2
2
 
3
- VERSION = '1.1.0'
3
+ VERSION = '2.0.0'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: username
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-24 00:00:00.000000000 Z
11
+ date: 2018-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -76,12 +76,12 @@ files:
76
76
  - LICENSE
77
77
  - README.md
78
78
  - app/models/concerns/username/model.rb
79
+ - app/models/concerns/username/model/devise.rb
79
80
  - lib/generators/templates/initializer.rb
80
81
  - lib/generators/username_generator.rb
81
82
  - lib/username.rb
82
83
  - lib/username/configuration.rb
83
84
  - lib/username/engine.rb
84
- - lib/username/railtie.rb
85
85
  - lib/username/version.rb
86
86
  homepage: https://github.com/jonhue/username
87
87
  licenses:
@@ -1,13 +0,0 @@
1
- require 'rails/railtie'
2
-
3
- module Username
4
- class Railtie < Rails::Railtie
5
-
6
- initializer 'username.initialize' do
7
- ActiveSupport.on_load :active_record do
8
- include Username::Model
9
- end
10
- end
11
-
12
- end
13
- end