katgut 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: a9e0af4382b30f4ec050991c18ef8518e2bfdd2b
4
- data.tar.gz: 3f15c268cbe282e31b9d8309488209b823f6ba9b
3
+ metadata.gz: 6e8469080830bb56b0884964cbf8b07ab6439fea
4
+ data.tar.gz: 0e77c797ec4131e6f658e93948adc3b4e2552afd
5
5
  SHA512:
6
- metadata.gz: 3c5858465324662443c5e0a797bcfbfd74bc887caf8a712f790ab96f112a4626f91c411c2e68d179b72b1e3aeb0c61f46803e3680a399f76af2026c7d2dccbcf
7
- data.tar.gz: 2c3c5dfbba597a2f256c8153f8eb9d7c96b9ad0118c4bda6a1baedd289bd1b64111136760d574c24d323543d68cf756e37d2bdfd79eb90304bd5537ca7c2fac5
6
+ metadata.gz: 945fe64304cdeeea0cf2b922ebadc932c589f7a4efe587254b6dc9985549abc0e95e581e3a3a937a9c014f91b0c23d55f8d8483a06958602962f437a38027b56
7
+ data.tar.gz: f78bf1a6b05833574776909cf5b600e7e53ed48b21793a2053576c08b316f630fa1a324b8efc36349c4afe27a1076d8306e3c527a1f9960bde81f682f9d1d15f
data/README.md CHANGED
@@ -50,6 +50,7 @@ The redirection rules will be stored in `katgut_rules` table. A rule is a set of
50
50
  ### `source`
51
51
  Set a unique key to determine which rule should be used to redirect the request.
52
52
  Only word characters and hyphens\(`[^a-zA-Z0-9_\-]`) are allowed and at least 5 characters needed.
53
+ If you don't give any value for the `source` attribute, katgut generates a random value automatically.
53
54
 
54
55
  ```
55
56
  /mount_point/:source
@@ -1,3 +1,5 @@
1
+ require 'securerandom'
2
+
1
3
  module Katgut
2
4
  class Rule < ActiveRecord::Base
3
5
  ALLOWED_SCHEMES = [:https, :http]
@@ -17,6 +19,8 @@ module Katgut
17
19
  length: { maximum: 255 }
18
20
  validate :ensure_destination_has_no_unallowed_scheme
19
21
 
22
+ after_initialize :set_random_source, if: -> { new_record? && source.nil? }
23
+
20
24
  def regular_destination
21
25
  if URI.extract(destination).present?
22
26
  destination
@@ -53,5 +57,9 @@ module Katgut
53
57
  errors.add(:destination, "has unallowed scheme.")
54
58
  end
55
59
  end
60
+
61
+ def set_random_source
62
+ self.source = SecureRandom.urlsafe_base64(6)
63
+ end
56
64
  end
57
65
  end
@@ -1,3 +1,3 @@
1
1
  module Katgut
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
Binary file
Binary file
@@ -751,3 +751,29 @@ ActionController::RoutingError (No route matches [GET] "/toritsugi_success.html"
751
751
  Rendered /Users/kazuki-hamada/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (27.1ms)
752
752
  Rendered /Users/kazuki-hamada/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (11.3ms)
753
753
  Rendered /Users/kazuki-hamada/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (164.8ms)
754
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
755
+ Migrating to AddRedirectionCountToRules (20160721095501)
756
+  (0.1ms) begin transaction
757
+  (0.2ms) ALTER TABLE "rules" ADD "redirection_count" integer DEFAULT 0 NOT NULL
758
+  (0.1ms) rollback transaction
759
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
760
+ Migrating to AddRedirectionCountToKatgutRules (20160721095501)
761
+  (0.1ms) begin transaction
762
+  (0.5ms) ALTER TABLE "katgut_rules" ADD "redirection_count" integer DEFAULT 0 NOT NULL
763
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20160721095501"]]
764
+  (0.6ms) commit transaction
765
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
766
+  (0.1ms)  SELECT sql
767
+ FROM sqlite_master
768
+ WHERE name='idx_katgut_source' AND type='index'
769
+ UNION ALL
770
+ SELECT sql
771
+ FROM sqlite_temp_master
772
+ WHERE name='idx_katgut_source' AND type='index'
773
+ 
774
+ Katgut::Rule Load (0.4ms) SELECT "katgut_rules".* FROM "katgut_rules" ORDER BY "katgut_rules"."id" ASC LIMIT 1
775
+ Katgut::Rule Exists (0.4ms) SELECT 1 AS one FROM "katgut_rules" WHERE "katgut_rules"."source" IS NULL LIMIT 1
776
+ Katgut::Rule Exists (0.5ms) SELECT 1 AS one FROM "katgut_rules" WHERE "katgut_rules"."source" IS NULL LIMIT 1
777
+ Katgut::Rule Exists (0.4ms) SELECT 1 AS one FROM "katgut_rules" WHERE "katgut_rules"."source" IS NULL LIMIT 1
778
+ Katgut::Rule Exists (0.2ms) SELECT 1 AS one FROM "katgut_rules" WHERE "katgut_rules"."source" IS NULL LIMIT 1
779
+ Katgut::Rule Exists (0.1ms) SELECT 1 AS one FROM "katgut_rules" WHERE "katgut_rules"."source" IS NULL LIMIT 1