card-mod-alias 0.11.5 → 0.13.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: fce2d278a69467daefce5f76122241a2a89b895e0f4f2a4a4acd367565acbee9
4
- data.tar.gz: 369d73e1686df3eff09121550aa912406696b9f9e1dc6e9b28e3289c249e7ecf
3
+ metadata.gz: 10b214b67c597a795b3da1370a2574a77cb3e335eea4a716ef1d5c2ac981113d
4
+ data.tar.gz: f1c89e427dead84215a10640a7568bdb27e2c3c6d7adf400b31fc8da6de61d0b
5
5
  SHA512:
6
- metadata.gz: 1f52be3ccc55d922524113e0f46d58bba871ff1152a2fb045b6f2aea16047ee6d5dba558f9906762f77146ea4093c01691a54cf6a9ac34d831348cfaae1fd300
7
- data.tar.gz: 02fcd442c379612bb78123ab6254bf31f104addd1cc1fc6158c1fcfa7d7b807e762c486e7f9366738f65f68c558465a95fa9ddefc2d07755a5d8866820d0f2b3
6
+ metadata.gz: 2d83cfae4eded1c624f9a4f2be776ab4b607e7a75ceec9577fa2626808aa3b97bb256e5f6ea379fffec974d5a53863a14cb459a42c00e8534bfedb382f64b735
7
+ data.tar.gz: b9d3d39b7bbae588ea2e6f99f29e5a2b030a46d0d54fe4c3e7b37d9b54e8393356f1db238daba63e14f8192582826da774f47d8abc9238b197d38f21daa83ccb
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ <!--
2
+ # @title README - mod: alias
3
+ -->
4
+
5
+ # Alias Mod
6
+ Enable Alias cards, which alias one simple card name to another.
7
+
8
+ The primary use case for alias cards is for handling redirects, for example after a card
9
+ has been renamed. Suppose, for example, a card's name is changed from *Former* to
10
+ *Current*. One can create an Alias card named "Former" with the content "Current". This
11
+ not only insures that links to /Former will be redirected to /Current, but it also
12
+ handles all descendants, redirecting /Former+field to /Current+field and /My+Former+Life
13
+ to /My+Current+Life.
14
+
15
+ Alias cards themselves must be simple cards and are not allowed to have children.
16
+
17
+ If a request to an alias specifies a view, eg `/Former?view=edit`, then the request
18
+ will not be redirected and will instead return the view of the Alias card itself.
19
+ Similarly, transactional requests (create, update, and delete) to the alias card
20
+ will take effect on the alias, not the target.
21
+
22
+ ## Cards with codenames
23
+
24
+ | codename | default name | purpose |
25
+ |:--------:|:------------:|:-------:|
26
+ | :alias | Alias | Cardtype of aliases |
27
+
28
+ ## Sets with code rules
29
+
30
+ ### {Card::Set::Type::Alias type: Alias}
31
+ An alias card's name is the alias's *source*, and its content is its target. So, in the
32
+ example above, the Alias card would be named *Former* and its content would be *Current*.
33
+
34
+ Content is stored as a card id.
35
+
36
+ #### Events
37
+
38
+ | event name | when | purpose |
39
+ |:---------:|:------:|:-------:|
40
+ | validate_alias_source | on save | ensures name is simple and card has no children |
41
+ | validate_alias_target | on save | ensures target is existing simple card |
42
+
43
+ ### {Card::Set::All::Alias All}
44
+
45
+ #### Events
46
+
47
+ | event name | when | purpose |
48
+ |:---------:|:------:|:-------:|
49
+ | create_alias_upon_rename | triggered | creates an alias from old name to new one |
50
+
51
+
52
+ #### HtmlFormat
53
+ Extends `#edit_name_buttons` so that when renaming, user is presented with a checkbox
54
+ to trigger the creation of an alias
55
+
56
+ ### {Card::Set::AllPlus::Alias All Plus}
57
+ Handle aliasing of compound names when at least one name part is an alias.
58
+
59
+ #### Events
60
+
61
+ | event name | when | purpose |
62
+ |:---------:|:------:|:-------:|
63
+ | validate_not_alias | on save | prevents creation of deescendents of aliases |
64
+
65
+ ## {CardController::Aliasing}
66
+ Module that enables card controller to handle alias-driven redirects and ensure that
67
+ transaction requests act upon the correct card (the alias when simple, the target when
68
+ compound).
@@ -7,6 +7,8 @@ class CardController
7
7
  hard_redirect target_url
8
8
  end
9
9
 
10
+ # create, read, and update requests take effect on the target card
11
+ # when aliases are compound (but on the alias card itself when simple).
10
12
  %i[create update delete].each do |action|
11
13
  define_method action do
12
14
  @card = card.target_card if card&.compound? && card&.alias?
@@ -16,12 +18,14 @@ class CardController
16
18
 
17
19
  private
18
20
 
21
+ # url to which aliased requests should be redirected
19
22
  def target_url
20
23
  target_params = params.clone.merge(mark: card.target_name).to_unsafe_h
21
24
  target_params.delete :controller
22
25
  card.target_card.format(:base).path target_params
23
26
  end
24
27
 
28
+ # aliased names are not redirected when a view is specified for a simple alias card
25
29
  def redirect_to_aliased?
26
30
  return false unless card&.alias?
27
31
 
data/set/all/alias.rb CHANGED
@@ -1,13 +1,16 @@
1
+ # triggerable event to auto-add an alias upon renaming a card
1
2
  event :create_alias_upon_rename, :finalize,
2
3
  on: :update, changed: :name, trigger: :required do
3
4
  add_subcard name_before_act, type_code: :alias, content: name
4
5
  end
5
6
 
7
+ # actual aliases override this in narrower sets.
6
8
  def alias?
7
9
  false
8
10
  end
9
11
 
10
12
  format :html do
13
+ # adds checkbox to rename form
11
14
  def edit_name_buttons
12
15
  output [auto_alias_checkbox, super].compact
13
16
  end
@@ -2,10 +2,12 @@ event :validate_not_alias, :validate, on: :save do
2
2
  errors.add t(:alias_cards_no_children) if alias? && type_code != :alias
3
3
  end
4
4
 
5
+ # a compound name is an alias if any part is an alias
5
6
  def alias?
6
7
  name.parts.any? { |p| Card[p]&.alias? }
7
8
  end
8
9
 
10
+ # reconstructs the name to which a compound name is aliased
9
11
  def target_name
10
12
  Card::Name[
11
13
  name.parts.map do |p|
data/set/type/alias.rb CHANGED
@@ -16,10 +16,12 @@ def alias?
16
16
  true
17
17
  end
18
18
 
19
+ # @return [Card::Name] name to which card's name is aliased
19
20
  def target_name
20
21
  first_name
21
22
  end
22
23
 
24
+ # @return [Card] card to which card is aliased
23
25
  def target_card
24
26
  first_card
25
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-alias
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.5
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-05-10 00:00:00.000000000 Z
13
+ date: 2021-08-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.101.5
21
+ version: 1.103.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.101.5
28
+ version: 1.103.0
29
29
  description: ''
30
30
  email:
31
31
  - info@decko.org
@@ -33,7 +33,7 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
- - config/initializers/init_aliasing.rb
36
+ - README.md
37
37
  - db/migrate_cards/20210504195646_add_alias_type.rb
38
38
  - lib/card_controller/aliasing.rb
39
39
  - set/all/alias.rb
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 3.1.4
68
+ rubygems_version: 3.1.6
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: Aliases
@@ -1 +0,0 @@
1
- CardController.include CardController::Aliasing