calib-rails 0.1.9 → 0.1.10
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 +4 -4
- data/lib/calib/controllers/basic_auth.rb +12 -11
- data/lib/calib/delegatable.rb +1 -1
- data/lib/calib/devise/friendly_forwardable.rb +5 -5
- data/lib/calib/devise/soft_deletion.rb +19 -8
- data/lib/calib/devise/soft_deletion_migration_enhancable.rb +27 -0
- data/lib/calib/rails/version.rb +1 -1
- data/lib/calib/soft_deletion/migration_enhancable.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfdcbe8fbfa7c4b62dcc3527dc8979d03f5c491690c832b7b9ec8f0d083ae05e
|
4
|
+
data.tar.gz: 5df15af026bd6823fbd0f262fe91faa1edd3307f99b81eb45eddbadee8c98409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66445fec8cff243bafa2e060f5a650741fd0a51004d968159604314997ce4e39e569d91fbe85ae9919e3f4d54b95e0ea21d31ccdb2c086c7e51ee27a97f0420f
|
7
|
+
data.tar.gz: 71fc441f650e9858bf7a82a40b8051539731f8f0fa857738147fae855101cadb639cbee5a1c9249518fb6344552827c2659b641ad6525454602e782a2552d0e2
|
@@ -2,19 +2,20 @@
|
|
2
2
|
# authenticated status stored in session.
|
3
3
|
# avoid frequently logging in
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
5
|
+
# === usage
|
6
|
+
# class ApplicationController < ActionController::Base
|
7
|
+
# include Calib::Controllers::BasicAuth
|
8
|
+
# basic_auth(user: 'myuser', pass: 'secret')
|
9
|
+
# ...
|
10
|
+
# end
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
12
|
+
# === options
|
13
|
+
# basic_auth # read ENV['BASIC_AUTH_USER'] and ENV['BASIC_AUTH_PASS']
|
14
|
+
# basic_auth(user: 'myuser', pass: 'secret') # standard
|
14
15
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
16
|
+
# basic_auth(user: 'myuser', pass: 'secret') do |request|
|
17
|
+
# request.domain != 'localhost' # localhost is unblocked domain.
|
18
|
+
# end
|
18
19
|
module Calib::Controllers::BasicAuth
|
19
20
|
extend ActiveSupport::Concern
|
20
21
|
|
data/lib/calib/delegatable.rb
CHANGED
@@ -5,7 +5,7 @@ module Calib::Delegatable
|
|
5
5
|
def self.delegate_all(targets)
|
6
6
|
targets = Array(targets)
|
7
7
|
define_method('method_missing') do |method, *args|
|
8
|
-
target = targets.find {|
|
8
|
+
target = targets.find {|t| t.respond_to?(method) }
|
9
9
|
return target.send(method, *args) if target.present?
|
10
10
|
super
|
11
11
|
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
# Redirect back to current page after sign in.
|
3
3
|
# @see https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
5
|
+
# === usage
|
6
|
+
# class ApplicationController < ActionController::Base
|
7
|
+
# include Calib::Devise::FriendlyForwardable
|
8
|
+
# ...
|
9
|
+
# end
|
10
10
|
module Calib::Devise::FriendlyForwardable
|
11
11
|
extend ActiveSupport::Concern
|
12
12
|
|
@@ -1,20 +1,27 @@
|
|
1
|
-
#
|
1
|
+
# == Soft deletation for devise
|
2
|
+
# use with SoftDeletionMigrationEnhancable
|
2
3
|
#
|
3
|
-
#
|
4
|
-
#
|
4
|
+
# === usage
|
5
|
+
# include to Devise Model.
|
5
6
|
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# t.index ["email", "alive"], name: "index_users_on_email_and_alive", unique: true, where: "(alive = 1)"
|
9
|
-
# [for mysql] # ignoring null column
|
10
|
-
# t.index ["email", "alive"], name: "index_users_on_email_and_alive", unique: true
|
7
|
+
# class User < ApplicationRecord
|
8
|
+
# include Calib::Devise::SoftDeletion
|
11
9
|
#
|
10
|
+
# devise :database_authenticatable, :registerable,
|
11
|
+
# :recoverable, :rememberable, :trackable, :validatable,
|
12
|
+
# :confirmable
|
13
|
+
#
|
14
|
+
# devise_soft_deletable # call below `device` method
|
15
|
+
#
|
16
|
+
# ...
|
17
|
+
# end
|
12
18
|
module Calib::Devise::SoftDeletion
|
13
19
|
extend ActiveSupport::Concern
|
14
20
|
|
15
21
|
included do
|
16
22
|
class_attribute :alive_column_name
|
17
23
|
|
24
|
+
# initialize method to call on Devise Model.
|
18
25
|
def self.devise_soft_deletable(alive_column_name = :alive)
|
19
26
|
self.alive_column_name = alive_column_name
|
20
27
|
|
@@ -41,18 +48,22 @@ module Calib::Devise::SoftDeletion
|
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
51
|
+
# check canceled
|
44
52
|
def canceled?
|
45
53
|
self.alive_value == nil
|
46
54
|
end
|
47
55
|
|
56
|
+
# do soft destroy
|
48
57
|
def soft_destroy
|
49
58
|
save if pre_destroy
|
50
59
|
end
|
51
60
|
|
61
|
+
# do soft destroy!
|
52
62
|
def soft_destroy!
|
53
63
|
save! if pre_destroy
|
54
64
|
end
|
55
65
|
|
66
|
+
# get alive_column_value
|
56
67
|
def alive_value
|
57
68
|
self.send(self.class.alive_column_name)
|
58
69
|
end
|
@@ -1,3 +1,30 @@
|
|
1
|
+
# == A Module for migration with soft deletation
|
2
|
+
# 1. unique email to ununique
|
3
|
+
# 2. email and _filter_column_ to composite unique
|
4
|
+
# 3. add colunn _caneled_at_column_ for storing canceled datetime
|
5
|
+
#
|
6
|
+
# === usage
|
7
|
+
# create migration file
|
8
|
+
#
|
9
|
+
# class ChangeForSoftDeletationToUsers < ActiveRecord::Migration[5.1]
|
10
|
+
# include Calib::Devise::SoftDeletionMigrationEnhancable
|
11
|
+
# def change
|
12
|
+
# change_for_device_soft_deletion(:users)
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# do migration
|
17
|
+
#
|
18
|
+
# and results on schema.rb:
|
19
|
+
#
|
20
|
+
# # with coulumn for soft_deleted_flag
|
21
|
+
# t.integer "alive", default: 1
|
22
|
+
#
|
23
|
+
# # unique indexes
|
24
|
+
# # [for postgresql] - partial indexes -
|
25
|
+
# t.index ["email", "alive"], name: "index_users_on_email_and_alive", unique: true, where: "(alive = 1)"
|
26
|
+
# # [for mysql] - ignoring null column -
|
27
|
+
# t.index ["email", "alive"], name: "index_users_on_email_and_alive", unique: true
|
1
28
|
module Calib::Devise::SoftDeletionMigrationEnhancable
|
2
29
|
include Calib::SoftDeletion::MigrationEnhancable
|
3
30
|
|
data/lib/calib/rails/version.rb
CHANGED
@@ -1,14 +1,32 @@
|
|
1
|
+
# == A Module for soft deletation on MySQL and PostgreSQL.
|
2
|
+
# with unique constraints(`deleted_at = nil` couldn't do it).
|
3
|
+
#
|
4
|
+
# === usage
|
5
|
+
# create migration file
|
6
|
+
#
|
7
|
+
# # Inlude this Modlule and edit.
|
8
|
+
# class AddNameToUsers < ActiveRecord::Migration[5.1]
|
9
|
+
# include Calib::SoftDeletion::MigrationEnhancable
|
10
|
+
# def change
|
11
|
+
# add_unique_column_for_soft_deletion :users, :name
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# and migrate
|
1
16
|
module Calib::SoftDeletion::MigrationEnhancable
|
17
|
+
# add unique column with soft deletation column as _filter_column_
|
2
18
|
def add_unique_column_for_soft_deletion(table, unique_column, filter_column = :alive)
|
3
19
|
add_column_for_soft_deletion(table, filter_column)
|
4
20
|
add_unique_index_for_soft_deletion(table, unique_column, filter_column)
|
5
21
|
end
|
6
22
|
|
23
|
+
# add column for soft deletation as _filter_column_
|
7
24
|
def add_column_for_soft_deletion(table, filter_column = :alive)
|
8
25
|
# @see https://qiita.com/yuba/items/70165875cfe02b03513d
|
9
26
|
add_column table, filter_column, :integer, default: 1 # if canceled, alive=NULL for MYSQL
|
10
27
|
end
|
11
28
|
|
29
|
+
# add unique index with soft deletation column as _filter_column_
|
12
30
|
def add_unique_index_for_soft_deletion(table, unique_column, filter_column = :alive)
|
13
31
|
if connection.adapter_name == 'MySQL'
|
14
32
|
add_index table, [unique_column, filter_column], unique: true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calib-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ms2sato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|