rtopia 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +26 -2
  2. data/VERSION +1 -1
  3. data/lib/rtopia.rb +25 -1
  4. data/rtopia.gemspec +51 -0
  5. metadata +3 -2
data/README.rdoc CHANGED
@@ -1,6 +1,30 @@
1
- = rtopia
1
+ = Rtopia
2
+
3
+ A very simple, but useful route generation helper for use anytime, anywhere.
4
+
5
+ == Assumptions
6
+
7
+ It checks for a `to_param`, and if Ruby1.9 or greater is used, checks for an `id`. Last fallback uses `to_s`.
8
+
9
+ == Examples
10
+
11
+ include Rtopia
12
+
13
+ R(:items) # => /items
14
+
15
+ # this appears to be redundant, take it with a grain of salt
16
+ # although it would probably be used for consistency's sake
17
+ R('/') # => '/'
18
+
19
+ @person = Person.new # has a to_param of john-doe
20
+ R(@person) # => '/john-doe'
21
+ R(@person, :posts) # => '/john-doe/posts'
22
+ R(@person, :posts, :replied) # => '/john-doe/posts/replied'
23
+
24
+ @entry = Entry.create # has an id of 1001 for example
25
+ R(@entry) # => '/1001'
26
+ R(:entry, @entry) # => '/entry/1001'
2
27
 
3
- Description goes here.
4
28
 
5
29
  == Note on Patches/Pull Requests
6
30
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/rtopia.rb CHANGED
@@ -5,10 +5,31 @@ module Rtopia
5
5
  @rtopia.R(*args)
6
6
  end
7
7
 
8
+ # Pass any collection of objects
9
+ # R will use it's :to_param, then :id (if ruby19), then :to_s
10
+ #
11
+ # Examples:
12
+ #
13
+ # R(:items) # => /items
14
+ #
15
+ # @person = Person.new # has a to_param of john-doe
16
+ # R(@person) # => '/john-doe'
17
+ # R(@person, :posts) # => '/john-doe/posts'
18
+ # R(@person, :posts, :replied) # => '/john-doe/posts/replied'
19
+ #
20
+ # @entry = Entry.create # has an id of 1001 for example
21
+ # R(@entry) # => '/1001'
22
+ # R(:entry, @entry) # => '/entry/1001'
23
+ #
8
24
  def R(*args)
9
25
  args.unshift('/').map { |arg| to_param(arg) }.join('/').squeeze('/')
10
26
  end
11
27
 
28
+ private
29
+ # Primary difference of this method is that it checks if
30
+ # the passed object has an :id method
31
+ # after checking for a :to_param
32
+ #
12
33
  def to_param_ruby19(object)
13
34
  if object.respond_to?(:to_param)
14
35
  object.to_param
@@ -18,7 +39,10 @@ module Rtopia
18
39
  object.to_s
19
40
  end
20
41
  end
21
-
42
+
43
+ # Since ruby 1.8 Objects all have a deprecated :id
44
+ # method which is also the same as its :object_id
45
+ # we can't just blindly check for an :id method
22
46
  def to_param_ruby18(object)
23
47
  if object.respond_to?(:to_param)
24
48
  object.to_param
data/rtopia.gemspec ADDED
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rtopia}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sinefunc"]
12
+ s.date = %q{2010-04-21}
13
+ s.description = %q{For use anywhere you have objects with to_params, ids, or just to_s's}
14
+ s.email = %q{sinefunc@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/rtopia.rb",
27
+ "rtopia.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_rtopia.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/sinefunc/rtopia}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.6}
35
+ s.summary = %q{A cute helper for route generation}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_rtopia.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ end
51
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sinefunc
@@ -35,6 +35,7 @@ files:
35
35
  - Rakefile
36
36
  - VERSION
37
37
  - lib/rtopia.rb
38
+ - rtopia.gemspec
38
39
  - test/helper.rb
39
40
  - test/test_rtopia.rb
40
41
  has_rdoc: true