rails_uri_parser 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ require 'rails/application'
2
+ require 'action_controller/metal/exceptions'
3
+ require "rails_uri_parser/version"
4
+
5
+ module RailsUriParser
6
+ def self.get_id(uri)
7
+ Rails.application.routes.recognize_path(uri)[:id]
8
+ rescue ActionController::RoutingError
9
+ # => return nil if route is bad
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module RailsUriParser
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../../lib/rails_uri_parser'
2
+
3
+ describe RailsUriParser do
4
+ describe 'getting the id from a board uri' do
5
+ subject { described_class.get_id(uri) }
6
+
7
+ let(:uri) { mock 'uri' }
8
+ let(:parsed_uri) { { id: id, format: :json } }
9
+ let(:id) { mock 'id' }
10
+
11
+ context 'when the uri is a valid uri' do
12
+ before do
13
+ Rails.stub_chain('application.routes.recognize_path').with(uri).and_return(parsed_uri)
14
+ end
15
+
16
+ it 'returns the id of the board' do
17
+ subject.should == id
18
+ end
19
+ end
20
+
21
+ context 'when the uri is not a valid board uri' do
22
+ before do
23
+ Rails.stub(:application) { raise ActionController::RoutingError, 'asdf' }
24
+ end
25
+
26
+ it 'returns nil' do
27
+ subject.should be_nil
28
+ end
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_uri_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Simpson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.11'
46
+ description: Provides simple parsing for our use of URIs in our RESTful APIs
47
+ email:
48
+ - matt.simpson3@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/rails_uri_parser.rb
54
+ - lib/rails_uri_parser/version.rb
55
+ - spec/lib/rails_uri_parser_spec.rb
56
+ homepage: https://github.com/ionicmobile/rails_uri_parser
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.24
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Provides simple parsing for our use of URIs in our RESTful APIs
80
+ test_files:
81
+ - spec/lib/rails_uri_parser_spec.rb
82
+ has_rdoc: