named-routes 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,10 +1,8 @@
1
1
  source :gemcutter
2
-
3
- gem "extlib", "0.9.15"
2
+ gemspec
4
3
 
5
4
  group :test do
6
5
  gem "diff-lcs", "1.1.2"
7
- gem "jeweler", "1.5.2"
8
6
  gem "rr", "1.0.2"
9
7
  gem "rspec", "2.3.0"
10
8
  end
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ named-routes (0.2.6)
5
+ activesupport (>= 3.0.0)
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
10
+ activesupport (3.0.9)
4
11
  diff-lcs (1.1.2)
5
- extlib (0.9.15)
6
- git (1.2.5)
7
- jeweler (1.5.2)
8
- bundler (~> 1.0.0)
9
- git (>= 1.2.5)
10
- rake
11
- rake (0.8.7)
12
12
  rr (1.0.2)
13
13
  rspec (2.3.0)
14
14
  rspec-core (~> 2.3.0)
@@ -24,7 +24,6 @@ PLATFORMS
24
24
 
25
25
  DEPENDENCIES
26
26
  diff-lcs (= 1.1.2)
27
- extlib (= 0.9.15)
28
- jeweler (= 1.5.2)
27
+ named-routes!
29
28
  rr (= 1.0.2)
30
29
  rspec (= 2.3.0)
data/Rakefile CHANGED
@@ -3,27 +3,20 @@ require 'rake/clean'
3
3
  require 'rake/testtask'
4
4
  require 'rake/rdoctask'
5
5
 
6
- begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |s|
9
- s.name = "named-routes"
10
- s.summary = "A simple and generic named routes api. It works really well with Sinatra."
11
- s.email = "brian.takita@gmail.com"
12
- s.homepage = "http://github.com/btakita/named-routes"
13
- s.summary = "A simple and generic named routes api. It works really well with Sinatra."
14
- s.authors = ["Brian Takita"]
15
- s.files = FileList[
16
- '[A-Z]*',
17
- '*.rb',
18
- 'lib/**/*.rb',
19
- 'spec/**/*.rb'
20
- ].to_a
21
- s.test_files = Dir.glob('spec/*_spec.rb')
22
- s.has_rdoc = true
23
- s.extra_rdoc_files = [ "README.md", "CHANGES" ]
24
- s.rdoc_options = ["--main", "README.md", "--inline-source", "--line-numbers"]
25
- s.add_dependency "extlib", ">= 0.9.15"
26
- end
27
- rescue LoadError
28
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
6
+ require 'rspec/core/rake_task'
7
+
8
+ desc 'Default: run specs.'
9
+ task :default => :spec
10
+
11
+ desc "Run specs"
12
+ RSpec::Core::RakeTask.new do |t|
13
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
14
+ # Put spec opts in a file named .rspec in root
15
+ end
16
+
17
+ desc "Generate code coverage"
18
+ RSpec::Core::RakeTask.new(:coverage) do |t|
19
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
20
+ t.rcov = true
21
+ t.rcov_opts = ['--exclude', 'spec']
29
22
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -2,103 +2,96 @@ module NamedRoutes
2
2
  class Routes
3
3
  class_inheritable_accessor :host, :prefix
4
4
 
5
- extend(Module.new do
6
- def instance
7
- @instance ||= new
8
- end
5
+ module Definition
6
+ extend ActiveSupport::Concern
9
7
 
10
- def http
11
- SchemedUri.new(self, "http")
12
- end
8
+ module InstanceMethods
9
+ def eval(*args)
10
+ self.class.eval(*args)
11
+ end
13
12
 
14
- def https
15
- SchemedUri.new(self, "https")
13
+ def as_json(*args)
14
+ self.class.defined_routes
15
+ end
16
16
  end
17
17
 
18
- def route(name, definition, include_prefix=true)
19
- full_definition = eval(definition, {}, :prefix => include_prefix)
20
- _defined_routes[name.to_s] = full_definition
21
- define_method name do |*args|
22
- self.class.eval(full_definition, [args.first].compact.first || {})
18
+ module ClassMethods
19
+ def instance
20
+ @instance ||= new
23
21
  end
24
- yield full_definition if block_given?
25
- full_definition
26
- end
27
- alias_method :path, :route
28
- alias_method :uri, :route
29
22
 
30
- def defined_routes
31
- (ancestors.reverse + [self]).inject({}) do |memo, klass|
32
- memo.merge!(klass._defined_routes) if klass.respond_to?(:_defined_routes)
33
- memo
23
+ def http
24
+ SchemedUri.new(self, "http")
34
25
  end
35
- end
36
26
 
37
- def _defined_routes
38
- @_defined_routes ||= {}
39
- end
27
+ def https
28
+ SchemedUri.new(self, "https")
29
+ end
40
30
 
41
- def eval(definition, params_arg={}, options={})
42
- full_definition = (options[:prefix] && prefix) ? File.join("", prefix, definition) : definition
43
- params = Mash.new(params_arg)
44
- uri_string = if params.empty?
31
+ def route(name, definition, include_prefix=true)
32
+ full_definition = eval(definition, {}, :prefix => include_prefix)
33
+ _defined_routes[name.to_s] = full_definition
34
+ define_method name do |*args|
35
+ self.class.eval(full_definition, [args.first].compact.first || {})
36
+ end
37
+ yield full_definition if block_given?
45
38
  full_definition
46
- else
47
- full_definition.split("/").map do |segment|
48
- segment_value = segment[/^:(.*)/, 1]
49
- segment_value_parts = segment_value.to_s.split(".")
50
- segment_name = segment_value_parts[0]
51
- if segment_name
52
- param_name = params.delete(File.basename(segment_name, '.*').to_s)
53
- URI.escape([param_name, *segment_value_parts[1..-1]].join("."))
54
- else
55
- segment
56
- end
57
- end.join("/")
58
39
  end
59
- unless params.empty?
60
- uri_string << "?#{escape_params(params).to_params.gsub("%20", "+")}"
40
+ alias_method :path, :route
41
+ alias_method :uri, :route
42
+
43
+ def defined_routes
44
+ (ancestors.reverse + [self]).inject({}) do |memo, klass|
45
+ memo.merge!(klass._defined_routes) if klass.respond_to?(:_defined_routes)
46
+ memo
47
+ end
61
48
  end
62
- uri_string
63
- end
64
49
 
65
- def escape_params(params={})
66
- params.inject({}) do |memo, kv|
67
- key, value = kv
68
- memo[URI.escape(key)] = if value.is_a?(Hash)
69
- escape_params(value)
70
- elsif value.is_a?(Array)
71
- value.map { |v| URI.escape(v.to_s) }
50
+ def _defined_routes
51
+ @_defined_routes ||= {}
52
+ end
53
+
54
+ def eval(definition, params_arg={}, options={})
55
+ full_definition = (options[:prefix] && prefix) ? File.join("", prefix, definition) : definition
56
+ params = HashWithIndifferentAccess.new(params_arg)
57
+ uri_string = if params.empty?
58
+ full_definition
72
59
  else
73
- URI.escape(value.to_s)
60
+ full_definition.split("/").map do |segment|
61
+ segment_value = segment[/^:(.*)/, 1]
62
+ segment_value_parts = segment_value.to_s.split(".")
63
+ segment_name = segment_value_parts[0]
64
+ if segment_name
65
+ param_name = params.delete(File.basename(segment_name, '.*').to_s)
66
+ URI.escape([param_name, *segment_value_parts[1..-1]].join("."))
67
+ else
68
+ segment
69
+ end
70
+ end.join("/")
71
+ end
72
+ unless params.empty?
73
+ uri_string << "?#{params.to_param}"
74
74
  end
75
- memo
75
+ uri_string
76
76
  end
77
- end
78
77
 
79
- def normalize(uri)
80
- uri.gsub(Regexp.new("^#{File.join("", prefix.to_s)}"), "/").gsub("//", "/")
81
- end
78
+ def normalize(uri)
79
+ uri.gsub(Regexp.new("^#{File.join("", prefix.to_s)}"), "/").gsub("//", "/")
80
+ end
82
81
 
83
- def as_json(*args)
84
- instance.as_json(*args)
85
- end
82
+ def as_json(*args)
83
+ instance.as_json(*args)
84
+ end
86
85
 
87
- def method_missing(method_name, *args, &block)
88
- if instance.respond_to?(method_name)
89
- instance.send(method_name, *args, &block)
90
- else
91
- super
86
+ def method_missing(method_name, *args, &block)
87
+ if instance.respond_to?(method_name)
88
+ instance.send(method_name, *args, &block)
89
+ else
90
+ super
91
+ end
92
92
  end
93
93
  end
94
- end)
95
-
96
- def eval(*args)
97
- self.class.eval(*args)
98
- end
99
-
100
- def as_json(*args)
101
- self.class.defined_routes
102
94
  end
95
+ include Definition
103
96
  end
104
97
  end
data/lib/named-routes.rb CHANGED
@@ -1,4 +1,8 @@
1
- require "extlib"
1
+ require "active_support"
2
+ require "active_support/concern"
3
+ require "active_support/hash_with_indifferent_access"
4
+ require "active_support/core_ext/object/to_query"
5
+ require "active_support/core_ext/class/inheritable_attributes"
2
6
  require "uri"
3
7
 
4
8
  module NamedRoutes
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: named-routes
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 5
9
- version: 0.2.5
4
+ prerelease:
5
+ version: 0.2.6
10
6
  platform: ruby
11
7
  authors:
12
8
  - Brian Takita
@@ -18,35 +14,16 @@ date: 2011-01-19 00:00:00 -08:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
- name: extlib
17
+ name: activesupport
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - "="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 9
31
- - 15
32
- version: 0.9.15
33
- type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: extlib
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
20
  none: false
40
21
  requirements:
41
22
  - - ">="
42
23
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 9
46
- - 15
47
- version: 0.9.15
24
+ version: 3.0.0
48
25
  type: :runtime
49
- version_requirements: *id002
26
+ version_requirements: *id001
50
27
  description:
51
28
  email: brian.takita@gmail.com
52
29
  executables: []
@@ -86,21 +63,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
63
  requirements:
87
64
  - - ">="
88
65
  - !ruby/object:Gem::Version
89
- segments:
90
- - 0
91
66
  version: "0"
92
67
  required_rubygems_version: !ruby/object:Gem::Requirement
93
68
  none: false
94
69
  requirements:
95
70
  - - ">="
96
71
  - !ruby/object:Gem::Version
97
- segments:
98
- - 0
99
72
  version: "0"
100
73
  requirements: []
101
74
 
102
75
  rubyforge_project:
103
- rubygems_version: 1.3.7
76
+ rubygems_version: 1.5.2
104
77
  signing_key:
105
78
  specification_version: 3
106
79
  summary: A simple and generic named routes api. It works really well with Sinatra.