rails-permalink 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rails-permalink.rb +38 -0
  2. metadata +64 -0
@@ -0,0 +1,38 @@
1
+ module Rails
2
+ module Permalink
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ # Specifies the given field as using permalink.
11
+ #
12
+ # class Foo < ActiveRecord::Base
13
+ #
14
+ # # stores the permalink version of title on permalink
15
+ # permalink :title
16
+ #
17
+ # # stores the permalink version of title on slug
18
+ # permalink :title, :slug
19
+ #
20
+ # end
21
+ #
22
+ def permalink(field_name, permalink_field_name = 'permalink')
23
+ before_save do |record|
24
+ if (record.send(permalink_field_name).blank?) || (record.send(field_name) && record.send(permalink_field_name).nil?)
25
+ record.send "#{permalink_field_name}=", record.send(field_name).parameterize
26
+ end
27
+ end
28
+
29
+ define_method "to_param" do
30
+ send(permalink_field_name)
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ ActiveRecord::Base.send :include, Rails::Permalink
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-permalink
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Francesc Esplugas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-05 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description:
27
+ email: contact@francescesplugas.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - lib/rails-permalink.rb
36
+ homepage: https://github.com/fesplugas/rails-permalink
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Permalink
63
+ test_files: []
64
+