friendly_id-mobility 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: 3beb3b78d2d0e0eccbc1405b0869f7b102c90e21
4
- data.tar.gz: dbe2b5819a7451ab66b1108aa5a3822d5190b480
3
+ metadata.gz: 69b790ec58bf14c3f05856bd1389093cadcdb1ef
4
+ data.tar.gz: 0aeace157739811519eac99348a10a71174ba40e
5
5
  SHA512:
6
- metadata.gz: 4b2b51f41c697f16c0288824bd589af0bd377cabfccf4dc366fbb859c37c8f06af68c086bb6c6971095f81cebd3b396d95587041033d96d1a8113afff7aecd65
7
- data.tar.gz: 1d810d14699b41e9ab04797820b2531fb94f75fa33f28b19d1c4f3bf9e54d347ade8ff5f6baa34413593463b9993c23b8ec3565d760e21d6dddbc802bce61918
6
+ metadata.gz: 72fe6766c35581feccb09092fda83af5c23fae059394a2b4baf8460e1127ce9ccb403a1c86de7a8878b52ad7726fbe34e5068754300b7afe01622cfe173572dd
7
+ data.tar.gz: c1cd04afb40ab7c4b96c27407a3daa1b0468e10bffd34ced4807bbee18264a8440a2be283039da0531e4b409e63a55ceeaf4fab5b001208e3b77f24ad6b4a233
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # FriendlyId Mobility Changelog
2
+
3
+ ## 0.3
4
+
5
+ ### 0.3.0
6
+ * Add support for history module ([#2](https://github.com/shioyama/friendly_id-mobility/pull/2))
7
+
8
+ ## 0.2.0
9
+ * Add support for translated slugs and translated base attributes
10
+
11
+ ## 0.1.0
12
+ * Mixin Mobility scope into FriendlyId scope
13
+
14
+
15
+
16
+
data/Gemfile CHANGED
@@ -10,4 +10,6 @@ group :development, :test do
10
10
 
11
11
  gem 'pry'
12
12
  gem 'pry-byebug'
13
+
14
+ gem 'guard-rspec'
13
15
  end
data/Gemfile.lock CHANGED
@@ -1,13 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- friendly_id-mobility (0.1.0)
4
+ friendly_id-mobility (0.2.0)
5
5
  friendly_id (>= 5.0.0, <= 5.3.0)
6
6
  mobility (~> 0.1.12)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ actionpack (5.0.2)
12
+ actionview (= 5.0.2)
13
+ activesupport (= 5.0.2)
14
+ rack (~> 2.0)
15
+ rack-test (~> 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
+ actionview (5.0.2)
19
+ activesupport (= 5.0.2)
20
+ builder (~> 3.1)
21
+ erubis (~> 2.7.0)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
11
24
  activemodel (5.0.2)
12
25
  activesupport (= 5.0.2)
13
26
  activerecord (5.0.2)
@@ -20,19 +33,54 @@ GEM
20
33
  minitest (~> 5.1)
21
34
  tzinfo (~> 1.1)
22
35
  arel (7.1.4)
36
+ builder (3.2.3)
23
37
  byebug (9.0.6)
24
38
  coderay (1.1.1)
25
39
  concurrent-ruby (1.0.5)
26
40
  database_cleaner (1.5.3)
27
41
  diff-lcs (1.3)
42
+ erubis (2.7.0)
43
+ ffi (1.9.18)
44
+ formatador (0.2.5)
28
45
  friendly_id (5.2.0)
29
46
  activerecord (>= 4.0.0)
47
+ generator_spec (0.9.3)
48
+ activesupport (>= 3.0.0)
49
+ railties (>= 3.0.0)
50
+ guard (2.14.1)
51
+ formatador (>= 0.2.4)
52
+ listen (>= 2.7, < 4.0)
53
+ lumberjack (~> 1.0)
54
+ nenv (~> 0.1)
55
+ notiffany (~> 0.0)
56
+ pry (>= 0.9.12)
57
+ shellany (~> 0.0)
58
+ thor (>= 0.18.1)
59
+ guard-compat (1.2.1)
60
+ guard-rspec (4.7.3)
61
+ guard (~> 2.1)
62
+ guard-compat (~> 1.1)
63
+ rspec (>= 2.99.0, < 4.0)
30
64
  i18n (0.8.1)
65
+ listen (3.1.5)
66
+ rb-fsevent (~> 0.9, >= 0.9.4)
67
+ rb-inotify (~> 0.9, >= 0.9.7)
68
+ ruby_dep (~> 1.2)
69
+ loofah (2.0.3)
70
+ nokogiri (>= 1.5.9)
71
+ lumberjack (1.0.11)
31
72
  method_source (0.8.2)
73
+ mini_portile2 (2.1.0)
32
74
  minitest (5.10.1)
33
75
  mobility (0.1.12)
34
76
  i18n (>= 0.6.10)
35
77
  request_store (~> 1.0)
78
+ nenv (0.3.0)
79
+ nokogiri (1.7.1)
80
+ mini_portile2 (~> 2.1.0)
81
+ notiffany (0.1.1)
82
+ nenv (~> 0.1)
83
+ shellany (~> 0.0)
36
84
  pry (0.10.4)
37
85
  coderay (~> 1.1.0)
38
86
  method_source (~> 0.8.1)
@@ -40,7 +88,24 @@ GEM
40
88
  pry-byebug (3.4.2)
41
89
  byebug (~> 9.0)
42
90
  pry (~> 0.10)
91
+ rack (2.0.1)
92
+ rack-test (0.6.3)
93
+ rack (>= 1.0)
94
+ rails-dom-testing (2.0.2)
95
+ activesupport (>= 4.2.0, < 6.0)
96
+ nokogiri (~> 1.6)
97
+ rails-html-sanitizer (1.0.3)
98
+ loofah (~> 2.0)
99
+ railties (5.0.2)
100
+ actionpack (= 5.0.2)
101
+ activesupport (= 5.0.2)
102
+ method_source
103
+ rake (>= 0.8.7)
104
+ thor (>= 0.18.1, < 2.0)
43
105
  rake (10.5.0)
106
+ rb-fsevent (0.9.8)
107
+ rb-inotify (0.9.8)
108
+ ffi (>= 0.5.0)
44
109
  request_store (1.3.2)
45
110
  rspec (3.5.0)
46
111
  rspec-core (~> 3.5.0)
@@ -55,8 +120,11 @@ GEM
55
120
  diff-lcs (>= 1.2.0, < 2.0)
56
121
  rspec-support (~> 3.5.0)
57
122
  rspec-support (3.5.0)
123
+ ruby_dep (1.5.0)
124
+ shellany (0.0.1)
58
125
  slop (3.6.0)
59
126
  sqlite3 (1.3.13)
127
+ thor (0.19.4)
60
128
  thread_safe (0.3.6)
61
129
  tzinfo (1.2.3)
62
130
  thread_safe (~> 0.1)
@@ -68,6 +136,8 @@ DEPENDENCIES
68
136
  bundler (~> 1.12)
69
137
  database_cleaner (~> 1.5.3)
70
138
  friendly_id-mobility!
139
+ generator_spec (~> 0.9.3)
140
+ guard-rspec
71
141
  pry
72
142
  pry-byebug
73
143
  rake
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/README.md CHANGED
@@ -16,7 +16,7 @@ Installation
16
16
  Add this line to your application's Gemfile:
17
17
 
18
18
  ```ruby
19
- gem 'friendly_id-mobility', '~> 0.2.0'
19
+ gem 'friendly_id-mobility', '~> 0.3.0'
20
20
  ```
21
21
 
22
22
  And then execute:
@@ -126,7 +126,7 @@ locale.
126
126
  ### Friendly Finders with Translated Attributes
127
127
 
128
128
  The Mobility `i18n` scope is mixed into the `friendly` scope for models which
129
- `use: mobility`, so you can find translated slugs just like you would an
129
+ `use: :mobility`, so you can find translated slugs just like you would an
130
130
  untranslated one:
131
131
 
132
132
  ```ruby
@@ -138,6 +138,35 @@ Article.friendly.find("mon-titre-foo")
138
138
  #=> #<Article id: 1 ...>
139
139
  ```
140
140
 
141
+ ### Slug History
142
+
143
+ To use the FriendlyId history module, use `use: [:history, :mobility]` when
144
+ calling `friendly_id` from your model:
145
+
146
+ ```ruby
147
+ class Article < ActiveRecord::Base
148
+ include Mobility
149
+ translates :slug, :title, dirty: true
150
+
151
+ extend FriendlyId
152
+ friendly_id :title, use: [:history, :mobility]
153
+ end
154
+ ```
155
+
156
+ It is important to have `:history` *before* `:mobility` here, since the
157
+ Mobility module looks for the presence of the history module and only adds
158
+ necessary overrides if history has been enabled (so the reverse order will not
159
+ work).
160
+
161
+ To use the history feature, you must add a `locale` column to your
162
+ `friendly_id_slugs` table, which you can do with the `friendly_id_mobility` generator:
163
+
164
+ ```
165
+ rails generate friendly_id_mobility
166
+ ```
167
+
168
+ Then run the generated migration with `rake db:migrate`.
169
+
141
170
  Contributing
142
171
  ------------
143
172
 
@@ -1,11 +1,17 @@
1
1
  require "friendly_id"
2
2
  require "friendly_id/mobility/version"
3
+ require "friendly_id/slug_decorator"
3
4
 
4
5
  module FriendlyId
5
6
  module Mobility
6
7
  class << self
7
8
  def setup(model_class)
8
9
  model_class.friendly_id_config.use :slugged
10
+ if model_class.friendly_id_config.uses? :history
11
+ model_class.instance_eval do
12
+ friendly_id_config.finder_methods = FriendlyId::Mobility::FinderMethods
13
+ end
14
+ end
9
15
  end
10
16
 
11
17
  def included(model_class)
@@ -51,5 +57,14 @@ module FriendlyId
51
57
  end
52
58
  end
53
59
  end)
60
+
61
+ module FinderMethods
62
+ include ::FriendlyId::History::FinderMethods
63
+
64
+ def exists_by_friendly_id?(id)
65
+ where(friendly_id_config.query_field => id).exists? ||
66
+ joins(:slugs).where(slug_history_clause(id)).exists?
67
+ end
68
+ end
54
69
  end
55
70
  end
@@ -1,5 +1,5 @@
1
1
  module FriendlyId
2
2
  module Mobility
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ require "friendly_id"
2
+
3
+ # This override must handle both the situation where locale column has been
4
+ # added to the slugs table, and also the situation where it has not.
5
+ #
6
+ FriendlyId::Slug.class_eval do
7
+ default_scope { column_names.include?("locale") ? where(locale: ::Mobility.locale) : all }
8
+
9
+ before_save do
10
+ self.locale ||= ::Mobility.locale if respond_to?(:locale=)
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+ require "rails/generators/active_record"
3
+
4
+ class FriendlyIdMobilityGenerator < ::Rails::Generators::Base
5
+ include ::Rails::Generators::Migration
6
+
7
+ desc "Generates migration to add locale column to friendly_id_slugs table."
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ def self.next_migration_number(dirname)
12
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
13
+ end
14
+
15
+ def create_migration_file
16
+ template = "add_locale_to_friendly_id_slugs"
17
+ migration_dir = File.expand_path("db/migrate")
18
+ if self.class.migration_exists?(migration_dir, template)
19
+ ::Kernel.warn "Migration already exists."
20
+ else
21
+ migration_template "migration.rb", "db/migrate/#{template}.rb"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ class AddLocaleToFriendlyIdSlugs < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ add_column :friendly_id_slugs, :locale, :string, null: :false, after: :scope
4
+
5
+ remove_index :friendly_id_slugs, [:slug, :sluggable_type]
6
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :locale], length: { slug: 140, sluggable_type: 50, locale: 2 }
7
+ remove_index :friendly_id_slugs, [:slug, :sluggable_type, :scope]
8
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope, :locale], length: { slug: 70, sluggable_type: 50, scope: 70, locale: 2 }, unique: true, name: :index_friendly_id_slugs_unique
9
+ add_index :friendly_id_slugs, :locale
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_id-mobility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-08 00:00:00.000000000 Z
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mobility
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
102
  version: 1.5.3
103
+ - !ruby/object:Gem::Dependency
104
+ name: generator_spec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.3
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.9.3
103
117
  description:
104
118
  email:
105
119
  - chris@dejimata.com
@@ -107,14 +121,19 @@ executables: []
107
121
  extensions: []
108
122
  extra_rdoc_files: []
109
123
  files:
124
+ - CHANGELOG.md
110
125
  - CODE_OF_CONDUCT.md
111
126
  - Gemfile
112
127
  - Gemfile.lock
128
+ - Guardfile
113
129
  - LICENSE.txt
114
130
  - README.md
115
131
  - Rakefile
116
132
  - lib/friendly_id/mobility.rb
117
133
  - lib/friendly_id/mobility/version.rb
134
+ - lib/friendly_id/slug_decorator.rb
135
+ - lib/generators/friendly_id_mobility_generator.rb
136
+ - lib/generators/templates/migration.rb
118
137
  homepage: https://github.com/shioyama/friendly_id-mobility
119
138
  licenses:
120
139
  - MIT