pseudocephalopod 0.3.1 → 0.3.2
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.
- data/README.md +1 -121
- data/Rakefile +5 -97
- data/lib/pseudocephalopod.rb +3 -78
- metadata +13 -101
- data/Gemfile +0 -20
- data/Gemfile.lock +0 -82
- data/lib/generators/pseudocephalopod/slug_migration/slug_migration_generator.rb +0 -24
- data/lib/generators/pseudocephalopod/slug_migration/templates/migration.erb +0 -12
- data/lib/generators/pseudocephalopod/slugs/slugs_generator.rb +0 -24
- data/lib/generators/pseudocephalopod/slugs/templates/migration.erb +0 -20
- data/lib/pseudocephalopod/active_record_methods.rb +0 -112
- data/lib/pseudocephalopod/caching.rb +0 -87
- data/lib/pseudocephalopod/finders.rb +0 -19
- data/lib/pseudocephalopod/memory_cache.rb +0 -29
- data/lib/pseudocephalopod/railtie.rb +0 -9
- data/lib/pseudocephalopod/scopes.rb +0 -13
- data/lib/pseudocephalopod/slug.rb +0 -36
- data/lib/pseudocephalopod/slug_history.rb +0 -41
- data/lib/pseudocephalopod/version.rb +0 -8
- data/pseudocephalopod.gemspec +0 -90
- data/test/caching_test.rb +0 -77
- data/test/helper.rb +0 -44
- data/test/is_sluggable_test.rb +0 -155
- data/test/model_definitions.rb +0 -19
- data/test/pseudocephalopod_test.rb +0 -27
- data/test/slug_history_test.rb +0 -86
data/README.md
CHANGED
@@ -1,123 +1,3 @@
|
|
1
1
|
# Pseudocephalopod #
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Pseudocephalopod is a simple slug library for ActiveRecord 3.0 plus.
|
6
|
-
|
7
|
-
It's main features are:
|
8
|
-
|
9
|
-
1. A very simple and tested codebase
|
10
|
-
2. Support for slug history (e.g. if a users slug changes, it will record the old slug)
|
11
|
-
3. Simple defaulting for slugs to UUID's (to avoid showing ID's.)
|
12
|
-
4. Built on ActiveRecord 3.0
|
13
|
-
5. If stringex is installed, uses stringex's transliteration stuff
|
14
|
-
|
15
|
-
Also, it's name is inspired by the Jason Wander series of books which I just happened to be
|
16
|
-
reading when I had the need for this.
|
17
|
-
|
18
|
-
### Why? ###
|
19
|
-
|
20
|
-
I love the idea of friendly\_id, and most of the implementation but it felt bloated
|
21
|
-
to me and my experiences on getting it to work correctly with Rails 3 left a base taste
|
22
|
-
in my mouth / was altogether hacky.
|
23
|
-
|
24
|
-
Pseudocephalopod is very much inspired by friendly id but with a much simpler codebase
|
25
|
-
and built to work on Rails 3 from the start.
|
26
|
-
|
27
|
-
## Usage ##
|
28
|
-
|
29
|
-
Using Pseudocephalopod is simple. In Rails, simply drop this in your Gemfile:
|
30
|
-
|
31
|
-
gem 'pseudocephalopod'
|
32
|
-
|
33
|
-
Optionally restricting the version.
|
34
|
-
|
35
|
-
Next, if you wish to use slug history run:
|
36
|
-
|
37
|
-
$ rails generate pseudocephalopod:slugs
|
38
|
-
|
39
|
-
Otherwise, when calling is\_sluggable make sure to include :history => false
|
40
|
-
|
41
|
-
Next, you need to add a cached slug column to your model and add an index. In your migration,
|
42
|
-
you'd usually want something like:
|
43
|
-
|
44
|
-
add_column :users, :cached_slug, :string
|
45
|
-
add_index :users, :cached_slug
|
46
|
-
|
47
|
-
Or, using our build in generator:
|
48
|
-
|
49
|
-
$ rails generate pseudocephalopod:slug_migration Model
|
50
|
-
|
51
|
-
Lastly, in your model, call is\_sluggable:
|
52
|
-
|
53
|
-
class User
|
54
|
-
is_sluggable :name
|
55
|
-
end
|
56
|
-
|
57
|
-
is\_sluggable accepts the source method name as a symbol, and an optional has of options including:
|
58
|
-
|
59
|
-
* _:sync_ - when source column changes, save the result. Defaults to true.
|
60
|
-
* _:convertor_ - a symbol (for a method) or block for how to generate the base slug. Defaults to :to\_url if available, parameterize otherwise.
|
61
|
-
* _:history_ - use slug history (e.g. if the name changes, it records the previous version in a slugs table). Defaults to true
|
62
|
-
* _:uuid_ - If the slug is blank, uses a generated uuid instead. Defaults to true
|
63
|
-
* _:slug\_column_ - the column in which to store the slug. Defaults to _:cached\_slug_
|
64
|
-
* _:to\_param_ - if true (by default), overrides to_param to use the slug
|
65
|
-
* _:use\_cache_ - uses Pseudocephalopod.cache if available to cache any lookups e.g. in memcache.
|
66
|
-
|
67
|
-
Once installed, it provides the following methods:
|
68
|
-
|
69
|
-
### User.find\_using\_slug "some-slug" ###
|
70
|
-
|
71
|
-
Finds a user from a slug (which can be the record's id, it's cached slug or, if enabled, slug history)
|
72
|
-
|
73
|
-
### User.other\_than(record) ###
|
74
|
-
|
75
|
-
Returns a relationship which returns records other than the given.
|
76
|
-
|
77
|
-
### User.with\_cached\_slug(record) ###
|
78
|
-
|
79
|
-
Returns a relationship which returns records with the given cached slug.
|
80
|
-
|
81
|
-
### User#generate\_slug ###
|
82
|
-
|
83
|
-
Forces the generation of a current slug
|
84
|
-
|
85
|
-
### User#generate\_slug! ###
|
86
|
-
|
87
|
-
Forces the generation of a current slug and saves it
|
88
|
-
|
89
|
-
### User#autogenerate\_slug ###
|
90
|
-
|
91
|
-
Generates a slug if not already present.
|
92
|
-
|
93
|
-
### User#has\_better\_slug? ###
|
94
|
-
|
95
|
-
When found via Model.find\_using\_slug, it will return try
|
96
|
-
if there is a better slug available. Intended for use in redirects etc.
|
97
|
-
|
98
|
-
## Working on Pseudocephalopod ##
|
99
|
-
|
100
|
-
To run tests, simply do the following:
|
101
|
-
|
102
|
-
bundle install
|
103
|
-
rake
|
104
|
-
|
105
|
-
And it's ready!
|
106
|
-
|
107
|
-
## Contributors ##
|
108
|
-
|
109
|
-
Thanks to the following who contributed functionality / bug fixes:
|
110
|
-
|
111
|
-
* [Matt Pruitt](http://github.com/guitsaru)
|
112
|
-
|
113
|
-
## Note on Patches/Pull Requests ##
|
114
|
-
|
115
|
-
* Fork the project.
|
116
|
-
* Make your feature addition or bug fix.
|
117
|
-
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
118
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
119
|
-
* Send me a pull request. Bonus points for topic branches.
|
120
|
-
|
121
|
-
## Copyright ##
|
122
|
-
|
123
|
-
Copyright (c) 2010 Darcy Laycock. See LICENSE for details.
|
3
|
+
Pseudocephalopod has been renamed - please see [Slugged](http://github.com/Sutto/slugged) instead.
|
data/Rakefile
CHANGED
@@ -1,110 +1,18 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
Bundler.setup
|
4
|
-
Bundler.require
|
5
|
-
|
6
1
|
require 'rake'
|
7
2
|
|
8
|
-
require File.expand_path('../lib/pseudocephalopod/version', __FILE__)
|
9
|
-
|
10
3
|
begin
|
11
4
|
require 'jeweler'
|
12
5
|
Jeweler::Tasks.new do |gem|
|
13
|
-
gem.version =
|
6
|
+
gem.version = "0.3.2"
|
14
7
|
gem.name = "pseudocephalopod"
|
15
|
-
gem.summary = %Q{
|
16
|
-
gem.description = %Q{
|
8
|
+
gem.summary = %Q{Renamed to slugged (http://github.com/Sutto/slugged)}
|
9
|
+
gem.description = %Q{Renamed to slugged (http://github.com/Sutto/slugged)}
|
17
10
|
gem.email = "sutto@sutto.net"
|
18
|
-
gem.homepage = "http://github.com/Sutto/
|
11
|
+
gem.homepage = "http://github.com/Sutto/slugged"
|
19
12
|
gem.authors = ["Darcy Laycock"]
|
20
|
-
gem.add_dependency "
|
21
|
-
gem.add_dependency "activesupport", "~> 3.0.0"
|
22
|
-
gem.add_dependency "uuid"
|
23
|
-
gem.add_development_dependency "shoulda", ">= 0"
|
24
|
-
gem.add_development_dependency "reversible_data"
|
13
|
+
gem.add_dependency "slugged"
|
25
14
|
end
|
26
15
|
Jeweler::GemcutterTasks.new
|
27
16
|
rescue LoadError
|
28
17
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
29
18
|
end
|
30
|
-
|
31
|
-
require 'rake/testtask'
|
32
|
-
Rake::TestTask.new(:test) do |test|
|
33
|
-
test.libs << 'lib' << 'test'
|
34
|
-
test.pattern = 'test/**/*_test.rb'
|
35
|
-
test.verbose = true
|
36
|
-
end
|
37
|
-
|
38
|
-
begin
|
39
|
-
require 'rcov/rcovtask'
|
40
|
-
Rcov::RcovTask.new do |test|
|
41
|
-
test.libs << 'test'
|
42
|
-
test.pattern = 'test/**/*_test.rb'
|
43
|
-
test.verbose = true
|
44
|
-
test.rcov_opts << '--exclude /gems/,/Library/,/usr/,lib/tasks,.bundle,config,/lib/rspec/,/lib/rspec-'
|
45
|
-
test.output_dir = "metrics/coverage"
|
46
|
-
end
|
47
|
-
rescue LoadError
|
48
|
-
task :rcov do
|
49
|
-
abort "Rcov isn't installed, please run via bundle exec after bundle installing"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
task :metrics => [:rcov, :saikuro, :reek, :flay, :flog, :roodi]
|
54
|
-
|
55
|
-
task :test => :check_dependencies
|
56
|
-
|
57
|
-
task :flog do
|
58
|
-
system "flog lib"
|
59
|
-
end
|
60
|
-
|
61
|
-
task :saikuro do
|
62
|
-
system "rm -rf metrics/saikuro && mkdir -p metrics/saikuro && saikuro -c -t -i lib/ -y 0 -w 11 -e 16 -o metrics/saikuro/"
|
63
|
-
end
|
64
|
-
|
65
|
-
begin
|
66
|
-
require 'flay'
|
67
|
-
require 'flay_task'
|
68
|
-
FlayTask.new
|
69
|
-
rescue LoadError
|
70
|
-
task :flay do
|
71
|
-
abort "Flay isn't installed, please run via bundle exec after bundle installing"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
begin
|
76
|
-
require 'reek/rake/task'
|
77
|
-
Reek::Rake::Task.new do |t|
|
78
|
-
t.fail_on_error = true
|
79
|
-
t.verbose = false
|
80
|
-
t.source_files = 'lib/**/*.rb'
|
81
|
-
end
|
82
|
-
rescue LoadError
|
83
|
-
task :reek do
|
84
|
-
abort "Reek isn't installed, please run via bundle exec after bundle installing"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
begin
|
89
|
-
require 'roodi'
|
90
|
-
require 'roodi_task'
|
91
|
-
RoodiTask.new do |t|
|
92
|
-
t.verbose = false
|
93
|
-
end
|
94
|
-
rescue LoadError
|
95
|
-
task :roodi do
|
96
|
-
abort "Roodi isn't installed, please run via bundle exec after bundle installing"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
task :default => :test
|
101
|
-
|
102
|
-
require 'rake/rdoctask'
|
103
|
-
Rake::RDocTask.new do |rdoc|
|
104
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
105
|
-
|
106
|
-
rdoc.rdoc_dir = 'rdoc'
|
107
|
-
rdoc.title = "pseudocephalopod #{version}"
|
108
|
-
rdoc.rdoc_files.include('README*')
|
109
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
110
|
-
end
|
data/lib/pseudocephalopod.rb
CHANGED
@@ -1,80 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require 'active_record'
|
3
|
-
require 'uuid'
|
1
|
+
require 'slugged'
|
4
2
|
|
5
|
-
|
6
|
-
require 'active_support/core_ext/module/attribute_accessors'
|
7
|
-
require 'active_support/concern'
|
3
|
+
warn 'Pseudocephalopod is now known as Slugged - see http://github.com/Sutto/slugged.'
|
8
4
|
|
9
|
-
|
10
|
-
extend ActiveSupport::Autoload
|
11
|
-
|
12
|
-
mattr_accessor :cache_key_prefix, :cache
|
13
|
-
|
14
|
-
class << self
|
15
|
-
|
16
|
-
def with_counter(prefix, counter = 0)
|
17
|
-
counter < 1 ? prefix : "#{prefix}--#{counter}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def next_value(scope, prefix)
|
21
|
-
counter = 0
|
22
|
-
slug = self.with_counter(prefix, counter)
|
23
|
-
while scope.with_cached_slug(slug).exists?
|
24
|
-
counter += 1
|
25
|
-
slug = self.with_counter(prefix, counter)
|
26
|
-
end
|
27
|
-
slug
|
28
|
-
end
|
29
|
-
|
30
|
-
def uuid
|
31
|
-
@uuid ||= UUID.new
|
32
|
-
end
|
33
|
-
|
34
|
-
def generate_uuid_slug
|
35
|
-
uuid.generate
|
36
|
-
end
|
37
|
-
|
38
|
-
def last_known_slug_id(scope, slug)
|
39
|
-
Pseudocephalopod::Slug.id_for(Pseudocephalopod.key_for_scope(scope), slug)
|
40
|
-
end
|
41
|
-
|
42
|
-
def record_slug(record, slug)
|
43
|
-
Pseudocephalopod::Slug.record_slug(record, slug)
|
44
|
-
end
|
45
|
-
|
46
|
-
def previous_slugs_for(record)
|
47
|
-
Pseudocephalopod::Slug.previous_for(record)
|
48
|
-
end
|
49
|
-
|
50
|
-
def remove_slug_history_for(record)
|
51
|
-
Pseudocephalopod::Slug.remove_history_for(record)
|
52
|
-
end
|
53
|
-
|
54
|
-
def key_for_scope(scope)
|
55
|
-
if scope.respond_to?(:slug_scope_key)
|
56
|
-
scope.slug_scope_key
|
57
|
-
elsif scope.class.respond_to?(:slug_scope_key)
|
58
|
-
scope.class.slug_scope_key
|
59
|
-
else
|
60
|
-
scope.to_s
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
self.cache_key_prefix ||= "cached-slugs"
|
67
|
-
|
68
|
-
autoload :Caching
|
69
|
-
autoload :Scopes
|
70
|
-
autoload :Finders
|
71
|
-
autoload :SlugHistory
|
72
|
-
autoload :Slug
|
73
|
-
autoload :MemoryCache
|
74
|
-
|
75
|
-
require 'pseudocephalopod/active_record_methods'
|
76
|
-
ActiveRecord::Base.extend Pseudocephalopod::ActiveRecordMethods
|
77
|
-
|
78
|
-
require 'pseudocephalopod/railtie' if defined?(Rails::Railtie)
|
79
|
-
|
80
|
-
end
|
5
|
+
Pseudocephalopod = Slugged
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pseudocephalopod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Darcy Laycock
|
@@ -15,46 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-30 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
name: slugged
|
22
23
|
prerelease: false
|
23
|
-
|
24
|
-
name: activerecord
|
25
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 7
|
31
|
-
segments:
|
32
|
-
- 3
|
33
|
-
- 0
|
34
|
-
- 0
|
35
|
-
version: 3.0.0
|
36
|
-
requirement: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
prerelease: false
|
39
|
-
type: :runtime
|
40
|
-
name: activesupport
|
41
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
hash: 7
|
47
|
-
segments:
|
48
|
-
- 3
|
49
|
-
- 0
|
50
|
-
- 0
|
51
|
-
version: 3.0.0
|
52
|
-
requirement: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
prerelease: false
|
55
|
-
type: :runtime
|
56
|
-
name: uuid
|
57
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
58
25
|
none: false
|
59
26
|
requirements:
|
60
27
|
- - ">="
|
@@ -63,36 +30,9 @@ dependencies:
|
|
63
30
|
segments:
|
64
31
|
- 0
|
65
32
|
version: "0"
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
type: :development
|
70
|
-
name: shoulda
|
71
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
version: "0"
|
80
|
-
requirement: *id004
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
prerelease: false
|
83
|
-
type: :development
|
84
|
-
name: reversible_data
|
85
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
|
-
requirements:
|
88
|
-
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
hash: 3
|
91
|
-
segments:
|
92
|
-
- 0
|
93
|
-
version: "0"
|
94
|
-
requirement: *id005
|
95
|
-
description: Super simple slugs for ActiveRecord 3.0 and higher, with support for slug history
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Renamed to slugged (http://github.com/Sutto/slugged)
|
96
36
|
email: sutto@sutto.net
|
97
37
|
executables: []
|
98
38
|
|
@@ -105,35 +45,12 @@ files:
|
|
105
45
|
- .document
|
106
46
|
- .gitignore
|
107
47
|
- .rvmrc
|
108
|
-
- Gemfile
|
109
|
-
- Gemfile.lock
|
110
48
|
- LICENSE
|
111
49
|
- README.md
|
112
50
|
- Rakefile
|
113
|
-
- lib/generators/pseudocephalopod/slug_migration/slug_migration_generator.rb
|
114
|
-
- lib/generators/pseudocephalopod/slug_migration/templates/migration.erb
|
115
|
-
- lib/generators/pseudocephalopod/slugs/slugs_generator.rb
|
116
|
-
- lib/generators/pseudocephalopod/slugs/templates/migration.erb
|
117
51
|
- lib/pseudocephalopod.rb
|
118
|
-
- lib/pseudocephalopod/active_record_methods.rb
|
119
|
-
- lib/pseudocephalopod/caching.rb
|
120
|
-
- lib/pseudocephalopod/finders.rb
|
121
|
-
- lib/pseudocephalopod/memory_cache.rb
|
122
|
-
- lib/pseudocephalopod/railtie.rb
|
123
|
-
- lib/pseudocephalopod/scopes.rb
|
124
|
-
- lib/pseudocephalopod/slug.rb
|
125
|
-
- lib/pseudocephalopod/slug_history.rb
|
126
|
-
- lib/pseudocephalopod/version.rb
|
127
|
-
- metrics/.gitignore
|
128
|
-
- pseudocephalopod.gemspec
|
129
|
-
- test/caching_test.rb
|
130
|
-
- test/helper.rb
|
131
|
-
- test/is_sluggable_test.rb
|
132
|
-
- test/model_definitions.rb
|
133
|
-
- test/pseudocephalopod_test.rb
|
134
|
-
- test/slug_history_test.rb
|
135
52
|
has_rdoc: true
|
136
|
-
homepage: http://github.com/Sutto/
|
53
|
+
homepage: http://github.com/Sutto/slugged
|
137
54
|
licenses: []
|
138
55
|
|
139
56
|
post_install_message:
|
@@ -165,11 +82,6 @@ rubyforge_project:
|
|
165
82
|
rubygems_version: 1.3.7
|
166
83
|
signing_key:
|
167
84
|
specification_version: 3
|
168
|
-
summary:
|
169
|
-
test_files:
|
170
|
-
|
171
|
-
- test/helper.rb
|
172
|
-
- test/is_sluggable_test.rb
|
173
|
-
- test/model_definitions.rb
|
174
|
-
- test/pseudocephalopod_test.rb
|
175
|
-
- test/slug_history_test.rb
|
85
|
+
summary: Renamed to slugged (http://github.com/Sutto/slugged)
|
86
|
+
test_files: []
|
87
|
+
|