Class: Reins::Routes::DSL
- Inherits:
-
Object
- Object
- Reins::Routes::DSL
- Defined in:
- lib/reins/routes/dsl.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#check(verb, path) ⇒ Object
Returns one of: - a Rack-callable (proc) when a rule matched verb+path - a Rack-callable returning [405, …] when path matched but verb did not - nil when no rule matched the path.
- #delete(path, dest = nil) ⇒ Object
- #get(path, dest = nil) ⇒ Object
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
- #match(path, dest = nil) ⇒ Object
- #patch(path, dest = nil) ⇒ Object
- #post(path, dest = nil) ⇒ Object
- #put(path, dest = nil) ⇒ Object
- #resources(name) ⇒ Object
- #root(dest) ⇒ Object
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
10 11 12 |
# File 'lib/reins/routes/dsl.rb', line 10 def initialize @rules = [] end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
8 9 10 |
# File 'lib/reins/routes/dsl.rb', line 8 def rules @rules end |
Instance Method Details
#check(verb, path) ⇒ Object
Returns one of:
- a Rack-callable (proc) when a rule matched verb+path
- a Rack-callable returning [405, ...] when path matched but verb did not
- nil when no rule matched the path
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/reins/routes/dsl.rb', line 36 def check(verb, path) path_only_match = false @rules.each do |rule| params = rule.match(verb, path) return resolve(rule.dest, params) if params path_only_match = true if rule.matches_path?(path) end return method_not_allowed(path) if path_only_match nil end |
#delete(path, dest = nil) ⇒ Object
18 |
# File 'lib/reins/routes/dsl.rb', line 18 def delete(path, dest = nil, **) = add(:delete, path, dest, **) |
#get(path, dest = nil) ⇒ Object
14 |
# File 'lib/reins/routes/dsl.rb', line 14 def get(path, dest = nil, **) = add(:get, path, dest, **) |
#match(path, dest = nil) ⇒ Object
24 25 26 |
# File 'lib/reins/routes/dsl.rb', line 24 def match(path, dest = nil, **) add(:all, path, dest, **) end |
#patch(path, dest = nil) ⇒ Object
17 |
# File 'lib/reins/routes/dsl.rb', line 17 def patch(path, dest = nil, **) = add(:patch, path, dest, **) |
#post(path, dest = nil) ⇒ Object
15 |
# File 'lib/reins/routes/dsl.rb', line 15 def post(path, dest = nil, **) = add(:post, path, dest, **) |
#put(path, dest = nil) ⇒ Object
16 |
# File 'lib/reins/routes/dsl.rb', line 16 def put(path, dest = nil, **) = add(:put, path, dest, **) |
#resources(name) ⇒ Object
28 29 30 |
# File 'lib/reins/routes/dsl.rb', line 28 def resources(name) Resources.new(self, name). end |
#root(dest) ⇒ Object
20 21 22 |
# File 'lib/reins/routes/dsl.rb', line 20 def root(dest, **) get("/", dest, **, as: :root) end |