url_keyed_object 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,25 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "url_keyed_object"
8
- gem.summary = %Q{Making it easy to work with objects with URL keys}
9
- gem.description = %Q{Making it easy to work with Rails objects which use a URL key in their URL instead of their database ID.}
10
- gem.email = "matt@reprocessed.org"
11
- gem.homepage = "http://github.com/fidothe/url_keyed_object"
12
- gem.authors = ["Matt Patterson"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_development_dependency "cucumber", ">= 0.5"
15
- gem.add_development_dependency "activerecord", ">= 2.3"
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
22
-
23
4
  require 'spec/rake/spectask'
24
5
  Spec::Rake::SpecTask.new(:spec) do |spec|
25
6
  spec.libs << 'lib' << 'spec'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -39,3 +39,8 @@ module UrlKeyedObject
39
39
  end
40
40
  end
41
41
  end
42
+
43
+ if defined?(Rails::Railtie)
44
+ require 'url_keyed_object/railtie'
45
+ end
46
+
@@ -2,13 +2,27 @@ require 'url_keyed_object'
2
2
  require 'active_record'
3
3
 
4
4
  module UrlKeyedObject
5
+ module ActiveRecordHook
6
+ def acts_as_url_keyed(opts = {})
7
+ attr_writer :url_key_length
8
+
9
+ @url_key_column = opts[:url_key_column] if opts.has_key?(:url_key_column)
10
+ @url_key_length = opts[:url_key_length] if opts.has_key?(:url_key_length)
11
+
12
+ send :include, UrlKeyedObject::ActiveRecord
13
+
14
+ before_create :generate_valid_url_key
15
+
16
+ define_method("#{url_key_column}=") { |value| logger.warn("Attempt to set ##{url_key_column}!"); nil }
17
+ end
18
+ end
19
+
5
20
  module ActiveRecord
6
21
  # def url_key=(value)
7
22
  # logger.warn('Attempt to set #url_key!')
8
23
  # nil
9
24
  # end
10
25
 
11
-
12
26
  module ClassMethods
13
27
  def url_key_column
14
28
  @url_key_column ||= :url_key
@@ -17,51 +31,33 @@ module UrlKeyedObject
17
31
  def url_key_length
18
32
  @url_key_length ||= 5
19
33
  end
20
-
21
- def acts_as_url_keyed(opts = {})
22
- attr_writer :url_key_length
23
-
24
- @url_key_column = opts[:url_key_column] if opts.has_key?(:url_key_column)
25
- @url_key_length = opts[:url_key_length] if opts.has_key?(:url_key_length)
26
-
27
- before_create :generate_valid_url_key
28
-
29
- include InstanceMethods
30
-
31
- define_method("#{url_key_column}=") { |value| logger.warn("Attempt to set ##{url_key_column}!"); nil }
32
- end
33
- end
34
-
35
- module InstanceMethods
36
- protected
37
-
38
- def generate_valid_url_key
39
- new_url_key = UrlKeyedObject.generate_checked_url_key(url_key_length) { |value| self.valid_url_key?(value) }
40
- write_attribute(url_key_column, new_url_key)
41
- end
42
-
43
- def valid_url_key?(url_key)
44
- self.class.send("find_by_#{url_key_column}", url_key).nil?
45
- end
46
-
47
- def url_key_column
48
- self.class.url_key_column
49
- end
50
-
51
- def url_key_length
52
- self.class.url_key_length
53
- end
54
-
55
-
56
- def to_param
57
- send url_key_column
58
- end
59
34
  end
60
35
 
61
36
  def self.included(model_class)
62
37
  model_class.extend ClassMethods
63
38
  end
39
+
40
+ def to_param
41
+ send url_key_column
42
+ end
43
+
44
+ protected
45
+
46
+ def generate_valid_url_key
47
+ new_url_key = UrlKeyedObject.generate_checked_url_key(url_key_length) { |value| self.valid_url_key?(value) }
48
+ write_attribute(url_key_column, new_url_key)
49
+ end
50
+
51
+ def valid_url_key?(url_key)
52
+ self.class.send("find_by_#{url_key_column}", url_key).nil?
53
+ end
54
+
55
+ def url_key_column
56
+ self.class.url_key_column
57
+ end
58
+
59
+ def url_key_length
60
+ self.class.url_key_length
61
+ end
64
62
  end
65
- end
66
-
67
- ActiveRecord::Base.send :include, UrlKeyedObject::ActiveRecord
63
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails'
2
+ require 'url_keyed_object/active_record'
3
+
4
+ module UrlKeyedObject
5
+ class Railtie < Rails::Railtie
6
+ initializer 'url_keyed_object.active_record_hook', :after => :preload_frameworks do
7
+ ::ActiveRecord::Base.extend UrlKeyedObject::ActiveRecordHook
8
+ end
9
+ end
10
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'url_keyed_object/active_record'
2
+
3
+ if defined?(ActiveRecord::Base)
4
+ ActiveRecord::Base.extend UrlKeyedObject::ActiveRecordHook
5
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url_keyed_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Matt Patterson
@@ -9,39 +14,49 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-20 00:00:00 +00:00
17
+ date: 2010-06-11 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
23
31
  version: 1.2.9
24
- version:
32
+ type: :development
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: cucumber
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 5
33
44
  version: "0.5"
34
- version:
45
+ type: :development
46
+ version_requirements: *id002
35
47
  - !ruby/object:Gem::Dependency
36
48
  name: activerecord
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
40
51
  requirements:
41
52
  - - ">="
42
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 2
56
+ - 3
43
57
  version: "2.3"
44
- version:
58
+ type: :development
59
+ version_requirements: *id003
45
60
  description: Making it easy to work with Rails objects which use a URL key in their URL instead of their database ID.
46
61
  email: matt@reprocessed.org
47
62
  executables: []
@@ -52,29 +67,15 @@ extra_rdoc_files:
52
67
  - LICENSE
53
68
  - README.rdoc
54
69
  files:
55
- - .document
56
- - .gitignore
57
- - LICENSE
70
+ - VERSION
58
71
  - README.rdoc
72
+ - LICENSE
59
73
  - Rakefile
60
- - VERSION
61
74
  - cucumber.yml
62
- - features/fixtures/.gitignore
63
- - features/for_url_key-like_uses.feature
64
- - features/step_definitions/database_steps.rb
65
- - features/step_definitions/eval_steps.rb
66
- - features/step_definitions/feedback_steps.rb
67
- - features/support/env.rb
68
- - features/support/hooks.rb
69
- - features/support/recording_logger.rb
70
- - features/with_active_record-basic.feature
71
- - features/with_active_record-more-advanced.feature
72
- - lib/url_keyed_object.rb
73
75
  - lib/url_keyed_object/active_record.rb
74
- - spec/spec.opts
75
- - spec/spec_helper.rb
76
- - spec/url_keyed_object/active_record_spec.rb
77
- - spec/url_keyed_object_spec.rb
76
+ - lib/url_keyed_object/railtie.rb
77
+ - lib/url_keyed_object.rb
78
+ - rails/init.rb
78
79
  has_rdoc: true
79
80
  homepage: http://github.com/fidothe/url_keyed_object
80
81
  licenses: []
@@ -88,22 +89,34 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
89
  requirements:
89
90
  - - ">="
90
91
  - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
91
94
  version: "0"
92
- version:
93
95
  required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  requirements:
95
97
  - - ">="
96
98
  - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
97
101
  version: "0"
98
- version:
99
102
  requirements: []
100
103
 
101
104
  rubyforge_project:
102
- rubygems_version: 1.3.5
105
+ rubygems_version: 1.3.6
103
106
  signing_key:
104
107
  specification_version: 3
105
108
  summary: Making it easy to work with objects with URL keys
106
109
  test_files:
110
+ - spec/spec.opts
107
111
  - spec/spec_helper.rb
108
112
  - spec/url_keyed_object/active_record_spec.rb
109
113
  - spec/url_keyed_object_spec.rb
114
+ - features/step_definitions/database_steps.rb
115
+ - features/step_definitions/eval_steps.rb
116
+ - features/step_definitions/feedback_steps.rb
117
+ - features/support/env.rb
118
+ - features/support/hooks.rb
119
+ - features/support/recording_logger.rb
120
+ - features/for_url_key-like_uses.feature
121
+ - features/with_active_record-basic.feature
122
+ - features/with_active_record-more-advanced.feature
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- url_keyed_object.gemspec
@@ -1 +0,0 @@
1
- *.sqlite3