only 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +23 -0
- data/README.md +0 -0
- data/lib/only.rb +33 -0
- data/lib/only/base_constraint.rb +23 -0
- data/lib/only/rails/routing.rb +7 -0
- data/lib/only/version.rb +3 -0
- metadata +64 -0
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright ©2011-2012 Corey Ward -- http://coreyward.me/
|
2
|
+
Copyright ©2012 Jones-Dilworth, Inc. -- http://www.jones-dilworth.com/
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
data/lib/only.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'only/base_constraint'
|
2
|
+
require 'only/rails/routing.rb'
|
3
|
+
|
4
|
+
module Only
|
5
|
+
class << self
|
6
|
+
def constraints
|
7
|
+
@constraints ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
# Options:
|
11
|
+
# :prefix
|
12
|
+
# :suffix
|
13
|
+
def allow(options = {})
|
14
|
+
prefix = options.delete :prefix
|
15
|
+
suffix = options.delete :suffix
|
16
|
+
|
17
|
+
# Extract the param attribute name and collection to match against
|
18
|
+
attribute_name, collection = options.first
|
19
|
+
|
20
|
+
# This is the name used for the DSL
|
21
|
+
name = attribute_name.to_s.pluralize
|
22
|
+
name = :"#{prefix}_#{name}" if prefix
|
23
|
+
name = :"#{name}_#{suffix}" if suffix
|
24
|
+
|
25
|
+
define(name) { collection.include? params[attribute_name] }
|
26
|
+
end
|
27
|
+
|
28
|
+
def define(name, &match_proc)
|
29
|
+
constraints[name] = Class.new(BaseConstraint)
|
30
|
+
constraints[name].define_singleton_method :condition_matches?, match_proc
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Only
|
2
|
+
class BaseConstraint
|
3
|
+
class << self
|
4
|
+
attr_accessor :request
|
5
|
+
|
6
|
+
def matches?(request)
|
7
|
+
self.request = request
|
8
|
+
condition_matches?
|
9
|
+
end
|
10
|
+
|
11
|
+
# Get the domain name from the request URL
|
12
|
+
def requested_domain
|
13
|
+
%r{//([^/]+)}.match(request.url)[1]
|
14
|
+
end
|
15
|
+
|
16
|
+
def params(attribute = nil)
|
17
|
+
attribute ? request.params[attribute] : request.params
|
18
|
+
end
|
19
|
+
end
|
20
|
+
private
|
21
|
+
def new; end
|
22
|
+
end
|
23
|
+
end
|
data/lib/only/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: only
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Corey Ward
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &2154422360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2154422360
|
25
|
+
description: Only makes writing route constraints for Rails 3+ applications easier
|
26
|
+
by providing a simple DSL and several helpers.
|
27
|
+
email:
|
28
|
+
- corey.atx@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/only/base_constraint.rb
|
34
|
+
- lib/only/rails/routing.rb
|
35
|
+
- lib/only/version.rb
|
36
|
+
- lib/only.rb
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
homepage: http://github.com/jonesdilworth/only
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.9.2
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.8'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.8
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Define Rails route constraints with ease
|
63
|
+
test_files: []
|
64
|
+
has_rdoc:
|