slugs 2.0.0 → 2.0.1

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
  SHA1:
3
- metadata.gz: ed7eaf4b4b662abd59ca80f68a4b0eb218a8e112
4
- data.tar.gz: f6b020ad3fbb60c5975c739831edab4becfe0f73
3
+ metadata.gz: 21b9bbbfe8b2a44f63ffb7edf8eaa22fe97cf6ce
4
+ data.tar.gz: 41e5ec36704f1c403c4cb62030cdbc83dc4e8fb9
5
5
  SHA512:
6
- metadata.gz: 9522dbe0945c8951ab468c51309e206e260effdcaaac090d8925c4c18b28d1d5ebebe90e7e8575cbdee51665a0916c3f352846add52f3548c7651491a1623e85
7
- data.tar.gz: ddb3e6688e11d140e0d87b13c6cb23ca2707d5e54868ecc18d1a09a38765aed3176cddc974662709234dbfbf13847b28fff3db45e66ddb9da35ca297e09a64d2
6
+ metadata.gz: 1096e6bdcdb42b39622b0a8175c9c2fe7928b1d29e09fd2c4eedf5d1b59745dc871d653f4279cf7277a935632e935ee13dabd573c684034ea4bb6839fd465bc1
7
+ data.tar.gz: 072aa30a88b10abad83b03a6b45fb65fc383af4d1c3a9e7495822d7d8778fe13e3f8d727b73a020d439f5347d203a19c4fe24536373ec800f5d4006a0185ac81
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Slugs
7
7
 
8
- Minimalistic slugs inspired in friendly_id for rails.
8
+ Manages slugs for records with minimal efford in rails.
9
9
 
10
10
  ## Install
11
11
 
@@ -21,6 +21,11 @@ $ bundle
21
21
 
22
22
  ## Configuration
23
23
 
24
+ Generate the slugs configuration file:
25
+ ```
26
+ bundle exec rails g slugs:install
27
+ ```
28
+
24
29
  Add the slug column to the tables of the models you want to have slugs:
25
30
  ```ruby
26
31
  t.string :slug
@@ -28,10 +33,17 @@ t.string :slug
28
33
 
29
34
  Update your db:
30
35
  ```
31
- rake db:migrate
36
+ bundle exec rake db:migrate
32
37
  ```
33
38
 
34
- NOTE: If you are using translatable_records you need to place the column in the translations table.
39
+ Configure the proc to decide which records will be slugged:
40
+ ```ruby
41
+ Slugs.configure do |config|
42
+ config.use_slug_proc = Proc.new do |record, params|
43
+ params[:controller] != 'admin'
44
+ end
45
+ end
46
+ ```
35
47
 
36
48
  ## Usage
37
49
 
@@ -47,18 +59,11 @@ To concatenate the value of multiple fields:
47
59
  has_slug :prop1, :prop2, :prop3
48
60
  ```
49
61
 
50
- If you need a very custom slug you can use a lambda, proc or block:
51
- ```ruby
52
- has_slug proc { |record| "#{record.prop}-custom" }
53
- ```
54
-
55
62
  To find a record by slug:
56
63
  ```ruby
57
- Model.slugged.find 'slug'
64
+ Model.find_by slug: 'slug'
58
65
  ```
59
66
 
60
- NOTE: All the path and url helpers will start using the slug by default.
61
-
62
67
  ## Credits
63
68
 
64
69
  This gem is maintained and funded by [mmontossi](https://github.com/mmontossi).
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Cronjobs
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ def create_definitions_file
10
+ copy_file 'configuration.rb', 'config/initializers/slugs.rb'
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ Slugs.configure do |config|
2
+
3
+ config.use_slug_proc = Proc.new do |record, params|
4
+ # Add your code here
5
+ end
6
+
7
+ end
data/lib/slugs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Slugs
2
2
 
3
- VERSION = '2.0.0'
3
+ VERSION = '2.0.1'
4
4
 
5
5
  end
@@ -1,5 +1,7 @@
1
1
  Slugs.configure do |config|
2
+
2
3
  config.use_slug_proc = Proc.new do |record, params|
3
4
  true
4
5
  end
6
+
5
7
  end
@@ -4188,3 +4188,75 @@ RoutesTest: test_optimized_url_helper
4188
4188
   (0.2ms) SELECT COUNT(*) FROM "shops" WHERE "shops"."slug" = $1 AND ("shops"."id" != $2) [["slug", "guitar-shop"], ["id", 234]]
4189
4189
   (0.1ms) RELEASE SAVEPOINT active_record_1
4190
4190
   (0.2ms) ROLLBACK
4191
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
4192
+  (0.3ms) BEGIN
4193
+ ------------------------------------
4194
+ GeneratorsTest: test_file_generation
4195
+ ------------------------------------
4196
+  (0.2ms) ROLLBACK
4197
+  (0.1ms) BEGIN
4198
+ ----------------------
4199
+ RecordsTest: test_save
4200
+ ----------------------
4201
+  (0.1ms) SAVEPOINT active_record_1
4202
+ SQL (0.4ms) INSERT INTO "users" ("first_name", "last_name", "slug") VALUES ($1, $2, $3) RETURNING "id" [["first_name", "Zakk"], ["last_name", "Wylde"], ["slug", "zakk-wylde"]]
4203
+  (0.3ms) SELECT COUNT(*) FROM "users" WHERE "users"."slug" = $1 AND ("users"."id" != $2) [["slug", "zakk-wylde"], ["id", 48]]
4204
+  (0.1ms) RELEASE SAVEPOINT active_record_1
4205
+  (0.1ms) SAVEPOINT active_record_1
4206
+ SQL (0.2ms) UPDATE "users" SET "slug" = $1 WHERE "users"."id" = $2 [["slug", "yngwie-malmsteen"], ["id", 48]]
4207
+  (0.2ms) SELECT COUNT(*) FROM "users" WHERE "users"."slug" = $1 AND ("users"."id" != $2) [["slug", "yngwie-malmsteen"], ["id", 48]]
4208
+  (0.1ms) RELEASE SAVEPOINT active_record_1
4209
+  (0.2ms) ROLLBACK
4210
+  (0.1ms) BEGIN
4211
+ ----------------------------
4212
+ RecordsTest: test_uniqueness
4213
+ ----------------------------
4214
+  (0.2ms) SAVEPOINT active_record_1
4215
+ SQL (0.3ms) INSERT INTO "shops" ("name", "slug") VALUES ($1, $2) RETURNING "id" [["name", "Guitar Shop"], ["slug", "guitar-shop"]]
4216
+  (0.2ms) SELECT COUNT(*) FROM "shops" WHERE "shops"."slug" = $1 AND ("shops"."id" != $2) [["slug", "guitar-shop"], ["id", 235]]
4217
+  (0.1ms) RELEASE SAVEPOINT active_record_1
4218
+  (0.1ms) SAVEPOINT active_record_1
4219
+ SQL (0.2ms) INSERT INTO "shops" ("name", "slug") VALUES ($1, $2) RETURNING "id" [["name", "Guitar Shop"], ["slug", "guitar-shop"]]
4220
+  (0.2ms) SELECT COUNT(*) FROM "shops" WHERE "shops"."slug" = $1 AND ("shops"."id" != $2) [["slug", "guitar-shop"], ["id", 236]]
4221
+ SQL (0.2ms) UPDATE "shops" SET "slug" = 'guitar-shop-236' WHERE "shops"."id" = $1 [["id", 236]]
4222
+  (0.1ms) RELEASE SAVEPOINT active_record_1
4223
+ Shop Load (0.3ms) SELECT "shops".* FROM "shops" ORDER BY "shops"."id" DESC LIMIT 1
4224
+  (0.2ms) SAVEPOINT active_record_1
4225
+ SQL (0.3ms) INSERT INTO "categories" ("name", "shop_id", "slug") VALUES ($1, $2, $3) RETURNING "id" [["name", "Gibson"], ["shop_id", 236], ["slug", "gibson"]]
4226
+  (0.2ms) SELECT COUNT(*) FROM "categories" WHERE "categories"."shop_id" = $1 AND "categories"."slug" = $2 AND ("categories"."id" != $3) [["shop_id", 236], ["slug", "gibson"], ["id", 98]]
4227
+  (0.2ms) RELEASE SAVEPOINT active_record_1
4228
+  (0.2ms) SAVEPOINT active_record_1
4229
+ SQL (0.2ms) INSERT INTO "categories" ("name", "shop_id", "slug") VALUES ($1, $2, $3) RETURNING "id" [["name", "Gibson"], ["shop_id", 236], ["slug", "gibson"]]
4230
+  (0.2ms) SELECT COUNT(*) FROM "categories" WHERE "categories"."shop_id" = $1 AND "categories"."slug" = $2 AND ("categories"."id" != $3) [["shop_id", 236], ["slug", "gibson"], ["id", 99]]
4231
+ SQL (0.2ms) UPDATE "categories" SET "slug" = 'gibson-99' WHERE "categories"."id" = $1 [["id", 99]]
4232
+  (0.1ms) RELEASE SAVEPOINT active_record_1
4233
+ Category Load (0.2ms) SELECT "categories".* FROM "categories" ORDER BY "categories"."id" DESC LIMIT 1
4234
+  (0.1ms) SAVEPOINT active_record_1
4235
+ SQL (0.2ms) INSERT INTO "products" ("name", "shop_id", "category_id", "slug") VALUES ($1, $2, $3, $4) RETURNING "id" [["name", "Les Paul"], ["shop_id", 236], ["category_id", 99], ["slug", "les-paul"]]
4236
+  (0.2ms) SELECT COUNT(*) FROM "products" WHERE "products"."shop_id" = $1 AND "products"."category_id" = $2 AND "products"."slug" = $3 AND ("products"."id" != $4) [["shop_id", 236], ["category_id", 99], ["slug", "les-paul"], ["id", 94]]
4237
+  (0.1ms) RELEASE SAVEPOINT active_record_1
4238
+  (0.1ms) SAVEPOINT active_record_1
4239
+ SQL (0.2ms) INSERT INTO "products" ("name", "shop_id", "category_id", "slug") VALUES ($1, $2, $3, $4) RETURNING "id" [["name", "Les Paul"], ["shop_id", 236], ["category_id", 99], ["slug", "les-paul"]]
4240
+  (0.2ms) SELECT COUNT(*) FROM "products" WHERE "products"."shop_id" = $1 AND "products"."category_id" = $2 AND "products"."slug" = $3 AND ("products"."id" != $4) [["shop_id", 236], ["category_id", 99], ["slug", "les-paul"], ["id", 95]]
4241
+ SQL (0.3ms) UPDATE "products" SET "slug" = 'les-paul-95' WHERE "products"."id" = $1 [["id", 95]]
4242
+  (0.1ms) RELEASE SAVEPOINT active_record_1
4243
+ Product Load (0.2ms) SELECT "products".* FROM "products" ORDER BY "products"."id" DESC LIMIT 1
4244
+  (0.2ms) ROLLBACK
4245
+  (0.1ms) BEGIN
4246
+ --------------------------
4247
+ RoutesTest: test_generator
4248
+ --------------------------
4249
+  (0.1ms) SAVEPOINT active_record_1
4250
+ SQL (0.2ms) INSERT INTO "shops" ("name", "slug") VALUES ($1, $2) RETURNING "id" [["name", "Guitar Shop"], ["slug", "guitar-shop"]]
4251
+  (0.2ms) SELECT COUNT(*) FROM "shops" WHERE "shops"."slug" = $1 AND ("shops"."id" != $2) [["slug", "guitar-shop"], ["id", 237]]
4252
+  (0.2ms) RELEASE SAVEPOINT active_record_1
4253
+  (0.2ms) ROLLBACK
4254
+  (0.1ms) BEGIN
4255
+ -------------------------------------
4256
+ RoutesTest: test_optimized_url_helper
4257
+ -------------------------------------
4258
+  (0.2ms) SAVEPOINT active_record_1
4259
+ SQL (0.2ms) INSERT INTO "shops" ("name", "slug") VALUES ($1, $2) RETURNING "id" [["name", "Guitar Shop"], ["slug", "guitar-shop"]]
4260
+  (0.2ms) SELECT COUNT(*) FROM "shops" WHERE "shops"."slug" = $1 AND ("shops"."id" != $2) [["slug", "guitar-shop"], ["id", 238]]
4261
+  (0.2ms) RELEASE SAVEPOINT active_record_1
4262
+  (0.1ms) ROLLBACK
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ require 'rails/generators'
3
+ require 'generators/slugs/install_generator'
4
+
5
+ class GeneratorsTest < Rails::Generators::TestCase
6
+
7
+ tests Cronjobs::Generators::InstallGenerator
8
+ destination Rails.root.join('tmp')
9
+
10
+ teardown do
11
+ FileUtils.rm_rf destination_root
12
+ end
13
+
14
+ test 'file generation' do
15
+ run_generator
16
+ assert_file 'config/initializers/slugs.rb'
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slugs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmontossi
@@ -54,6 +54,8 @@ files:
54
54
  - MIT-LICENSE
55
55
  - README.md
56
56
  - Rakefile
57
+ - lib/generators/slugs/install_generator.rb
58
+ - lib/generators/slugs/templates/configuration.rb
57
59
  - lib/slugs.rb
58
60
  - lib/slugs/concern.rb
59
61
  - lib/slugs/configuration.rb
@@ -108,6 +110,7 @@ files:
108
110
  - test/dummy/public/422.html
109
111
  - test/dummy/public/500.html
110
112
  - test/dummy/public/favicon.ico
113
+ - test/generator_test.rb
111
114
  - test/records_test.rb
112
115
  - test/routes_test.rb
113
116
  - test/test_helper.rb
@@ -182,6 +185,7 @@ test_files:
182
185
  - test/dummy/public/500.html
183
186
  - test/dummy/public/favicon.ico
184
187
  - test/dummy/Rakefile
188
+ - test/generator_test.rb
185
189
  - test/records_test.rb
186
190
  - test/routes_test.rb
187
191
  - test/test_helper.rb