avocado 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e32ef0766b1e70a3d4946f2d512acc59e5fe7d08e7166a751dbb3e5eacc35b41
4
- data.tar.gz: a822265796d94d9e5d4174894f6a7dea7bf7d845d0ac78eb65686a4ecab7f3cd
3
+ metadata.gz: 9b2bf2a8946882c7f2c799f8f545f34d3d34c6d3a64a932258350e57b32fdabe
4
+ data.tar.gz: 0f2430fff76f6912de3b1f09d08ab9b12858fa245e278e5542341eddfe116314
5
5
  SHA512:
6
- metadata.gz: 4f3c42f3873e26eec8f11047b5fd5bbf885ccc4dd350aea52f872b3d869dd19917ff24c71a0989fbf1d7a547388a0ddd578ea0cb05eaacb12b8d6962cfb99af7
7
- data.tar.gz: f3b23cc9b7df23daabe61e9143aea880bd4183b47126c5bea515df271896c42498513add9776eff8c73302f95c3f6097f5acbc9ff360f9c77508817bf1cb56c9
6
+ metadata.gz: 547b8e2c1e35508a75828c4f735b021c1022fe6e9e70f4a41c33dbb2d823592ff86d65732475c72fb3ee5cac0a3bed3f74c1fc12521b4344cc743313b6ed922c
7
+ data.tar.gz: 016be93303ef00a75c3e7a63e2a1d030f2955eb7eaf92d80ab03fed4704da6fecc5b194d6a73e567e524087063dd2b1e947799fd5f0f338eba20a6f25f585831
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-07-15
4
+
5
+ - Validate presence, uniqueness, and format on `email` attribute
6
+ - Normalize email value during save
7
+ - Validate password format and length
8
+ - Include a token generator for password recovery
9
+ - Rename `Avocado::UserConcern` to `Avocado::User`
10
+
3
11
  ## [0.1.0] - 2023-07-14
4
12
 
5
13
  - Initial release
data/README.md CHANGED
@@ -15,18 +15,24 @@ Without bundler, install the gem by executing:
15
15
  ## Usage
16
16
 
17
17
  If you have a `User` model in your application and are nervous about using Rails
18
- features directly, preferring to consume the features via a packaged gem, you
19
- can use the Rails `has_secure_password` feature in a more convoluted way, by
20
- adding the `Avocado::UserConcern` to your `User` model:
18
+ features directly, preferring to consume the features via a packaged gem, add
19
+ the `Avocado::User` to your `User` model:
21
20
 
22
21
  ```ruby
23
22
  class User < ApplicationRecord
24
- include Avocado::UserConcern
23
+ include Avocado::User
25
24
  end
26
25
  ```
27
26
 
28
- Note that behind the scenes this is truly just calling `has_secure_password` for
29
- you and doing nothing else. It's sort of funny to do this.
27
+ This will do a few things behind the scenes:
28
+
29
+ - Use the built-in `has_secure_password` to generate relevant password methods
30
+ - Add some basic validations for the `email` and `password` fields on `User`
31
+ - Normalize email values when records are saved
32
+ - Provide a token generator for password recovery
33
+
34
+ It's sort of funny to do this because you genuinely just could have put this
35
+ stuff right in your app, and yet here we are making gems instead!
30
36
 
31
37
  ## Development
32
38
 
@@ -3,11 +3,12 @@
3
3
  require "active_support/concern"
4
4
 
5
5
  module Avocado
6
- module UserConcern
6
+ module User
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
- has_secure_password
10
+ include UserEmailConcern
11
+ include UserPasswordConcern
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Avocado
6
+ module UserEmailConcern
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ validates :email, presence: true, uniqueness: true, format: {with: URI::MailTo::EMAIL_REGEXP}
11
+
12
+ normalizes :email, with: ->(email) { email.downcase.strip }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Avocado
6
+ module UserPasswordConcern
7
+ extend ActiveSupport::Concern
8
+
9
+ REQUIRED_FORMAT = /\A(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*\z/x
10
+ REQUIRED_LENGTH = 8
11
+ TOKEN_EXPIRATION = 64.minutes
12
+
13
+ included do
14
+ has_secure_password
15
+
16
+ validates :password, format: {with: REQUIRED_FORMAT}, length: {minimum: REQUIRED_LENGTH}, allow_nil: true
17
+
18
+ generates_token_for :password_recovery, expires_in: TOKEN_EXPIRATION do
19
+ password_digest_salt
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def password_digest_salt
26
+ BCrypt::Password.new(password_digest).salt[-10..]
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avocado
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/avocado.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "avocado/version"
4
- require_relative "avocado/user_concern"
5
4
 
6
5
  module Avocado
7
6
  class Error < StandardError; end
7
+
8
+ autoload :User, "avocado/user"
9
+ autoload :UserEmailConcern, "avocado/user_email_concern"
10
+ autoload :UserPasswordConcern, "avocado/user_password_concern"
8
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avocado
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Jankowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-14 00:00:00.000000000 Z
11
+ date: 2023-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt
@@ -82,7 +82,9 @@ files:
82
82
  - Rakefile
83
83
  - config.ru
84
84
  - lib/avocado.rb
85
- - lib/avocado/user_concern.rb
85
+ - lib/avocado/user.rb
86
+ - lib/avocado/user_email_concern.rb
87
+ - lib/avocado/user_password_concern.rb
86
88
  - lib/avocado/version.rb
87
89
  - sig/avocado.rbs
88
90
  homepage: https://github.com/unicorngroomers/avocado