Class: Sinatra::Scope
- Inherits:
-
Object
- Object
- Sinatra::Scope
- Defined in:
- lib/sinatra/scopes.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #create_action(http_method, pattern, &blk) ⇒ Object
- #get(pattern, &blk) ⇒ Object
-
#initialize(app, pattern, &blk) ⇒ Scope
constructor
A new instance of Scope.
- #post(pattern, &blk) ⇒ Object
Constructor Details
#initialize(app, pattern, &blk) ⇒ Scope
Returns a new instance of Scope.
5 6 7 8 9 |
# File 'lib/sinatra/scopes.rb', line 5 def initialize(app, pattern, &blk) @app = app @pattern = pattern || '' @block = blk end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
11 12 13 |
# File 'lib/sinatra/scopes.rb', line 11 def block @block end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
11 12 13 |
# File 'lib/sinatra/scopes.rb', line 11 def pattern @pattern end |
Instance Method Details
#create_action(http_method, pattern, &blk) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/sinatra/scopes.rb', line 13 def create_action(http_method, pattern, &blk) scope = self @app.send(http_method, scope.pattern + pattern) do |*args| # run the scope block self.instance_exec(*args[0...scope.block.arity], &scope.block) # run the action block self.instance_exec(*args[scope.block.arity..-1], &blk) end end |
#get(pattern, &blk) ⇒ Object
23 24 25 |
# File 'lib/sinatra/scopes.rb', line 23 def get(pattern, &blk) create_action :get, pattern, &blk end |
#post(pattern, &blk) ⇒ Object
27 28 29 |
# File 'lib/sinatra/scopes.rb', line 27 def post(pattern, &blk) create_action :post, pattern, &blk end |