rtopia 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
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
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Sinefunc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = rtopia
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Sinefunc. See LICENSE for details.
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rtopia"
8
+ gem.summary = %Q{A cute helper for route generation}
9
+ gem.description = %Q{For use anywhere you have objects with to_params, ids, or just to_s's}
10
+ gem.email = "sinefunc@gmail.com"
11
+ gem.homepage = "http://github.com/sinefunc/rtopia"
12
+ gem.authors = ["Sinefunc"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "rtopia #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,35 @@
1
+ module Rtopia
2
+ def self.R(*args)
3
+ @rtopia ||= Object.new.extend(self)
4
+
5
+ @rtopia.R(*args)
6
+ end
7
+
8
+ def R(*args)
9
+ args.unshift('/').map { |arg| to_param(arg) }.join('/').squeeze('/')
10
+ end
11
+
12
+ def to_param_ruby19(object)
13
+ if object.respond_to?(:to_param)
14
+ object.to_param
15
+ elsif object.respond_to?(:id)
16
+ object.id
17
+ else
18
+ object.to_s
19
+ end
20
+ end
21
+
22
+ def to_param_ruby18(object)
23
+ if object.respond_to?(:to_param)
24
+ object.to_param
25
+ else
26
+ object.to_s
27
+ end
28
+ end
29
+
30
+ if RUBY_VERSION >= "1.9"
31
+ alias to_param to_param_ruby19
32
+ else
33
+ alias to_param to_param_ruby18
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'rtopia'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,63 @@
1
+ require 'helper'
2
+
3
+ module RtopiaRuby18
4
+ include Rtopia
5
+
6
+ alias to_param to_param_ruby18
7
+ end
8
+
9
+ module String18
10
+ def id
11
+ 1001
12
+ end
13
+ end
14
+
15
+ class Person < Struct.new(:name)
16
+ alias to_param name
17
+ end
18
+
19
+ class Entry < Struct.new(:id)
20
+ end
21
+
22
+ class TestRtopia < Test::Unit::TestCase
23
+ include Rtopia
24
+
25
+ def setup
26
+ @ruby18 = Object.new
27
+ @ruby18.extend RtopiaRuby18
28
+ end
29
+
30
+ def test_R_of_slash_is_slash
31
+ assert_equal '/', R('/')
32
+ end
33
+
34
+ def test_R_of_items_is_slash_items
35
+ assert_equal '/items', R(:items)
36
+ end
37
+
38
+ def test_R_of_person_named_john_is_john
39
+ assert_equal '/john', R(Person.new('john'))
40
+ end
41
+
42
+ def test_R_of_person_named_john_with_items_new_is_john_items_new
43
+ assert_equal '/john/items/new', R(Person.new('john'), :items, :new)
44
+ end
45
+
46
+ def test_R_of_items_and_string_1_is_items_1_when_ruby18
47
+ @string_with_id = '1'.extend(String18)
48
+
49
+ assert_equal '/items/1', @ruby18.R(:items, @string_with_id)
50
+ end
51
+
52
+ def test_R_of_items_and_int_1_is_items_1
53
+ assert_equal '/items/1', @ruby18.R(:items, 1)
54
+ end
55
+
56
+ def test_R_of_entries_entry_with_id_10_is_entries_10
57
+ assert_equal '/entries/10', R(:entries, Entry.new(10))
58
+ end
59
+
60
+ def test_Rtopia_R_is_calleable_directly
61
+ assert_equal '/items/yeah/boi', Rtopia.R(:items, :yeah, :boi)
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtopia
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Sinefunc
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-21 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: For use anywhere you have objects with to_params, ids, or just to_s's
22
+ email: sinefunc@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - VERSION
37
+ - lib/rtopia.rb
38
+ - test/helper.rb
39
+ - test/test_rtopia.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/sinefunc/rtopia
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.6
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A cute helper for route generation
70
+ test_files:
71
+ - test/helper.rb
72
+ - test/test_rtopia.rb