stumb 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,24 +2,24 @@ require 'rubygems'
2
2
  require 'rack'
3
3
 
4
4
  module Stumb
5
- autoload :Stub, 'stumb/stub'
5
+ autoload :Store, 'stumb/store'
6
6
  autoload :Stamp, 'stumb/stamp'
7
7
  autoload :StampSheet, 'stumb/stamp_sheet'
8
8
  autoload :Servlet, 'stumb/servlet'
9
9
 
10
- Version = '0.1.0'
10
+ Version = '0.1.1'
11
11
 
12
12
  def to_app(sheet_path = "/sheet", &block)
13
13
  Rack::Builder.new {
14
14
  use Rack::ShowExceptions
15
15
 
16
- stub = Stub.new(200, {}, "")
17
- sheet = StampSheet.new(stub)
16
+ store = Store.new
17
+ sheet = StampSheet.new(store)
18
18
 
19
19
  map(sheet_path) { run sheet }
20
20
 
21
21
  sinatra = Class.new(Servlet)
22
- sinatra.storage = stub
22
+ sinatra.storage = store
23
23
  sinatra.class_eval(&block)
24
24
 
25
25
  map("/") { run sinatra }
@@ -3,7 +3,7 @@ require 'sinatra'
3
3
  module Stumb
4
4
  class Servlet < Sinatra::Base
5
5
  def self.store(req)
6
- @store.stamps << Stamp.new(req.dup)
6
+ @store.store(Stamp.new(req.dup))
7
7
  end
8
8
 
9
9
  def self.storage=(store)
@@ -1,5 +1,5 @@
1
1
  :ruby
2
- title = "#{stamps.size} requests - Stumb, stub and show requests."
2
+ title = "#{store.size} requests - Stumb, stub and show requests."
3
3
  !!!
4
4
  %html
5
5
  %head
@@ -53,7 +53,7 @@
53
53
  font-size: 12px
54
54
  %body
55
55
  %h1&= title
56
- - stamps.reverse.each do |stamp|
56
+ - store.each do |stamp|
57
57
  %div.stump{:id => stamp.object_id}
58
58
  %h2
59
59
  %span.method&= stamp.request.request_method
@@ -3,12 +3,14 @@ require 'time'
3
3
 
4
4
  module Stumb
5
5
  class StampSheet
6
- def initialize(stub)
7
- @stub = stub
6
+ attr_reader :store
7
+
8
+ def initialize(store)
9
+ @store = store
8
10
  end
9
11
 
10
12
  def call(env)
11
- [200, {"Content-Type" => "text/html"}, template.render(@stub)]
13
+ [200, {"Content-Type" => "text/html"}, template.render(self)]
12
14
  end
13
15
 
14
16
  private
@@ -0,0 +1,30 @@
1
+ require 'monitor'
2
+
3
+ module Stumb
4
+ class Store
5
+ include Enumerable
6
+ include MonitorMixin
7
+
8
+ def initialize
9
+ super()
10
+ @store = []
11
+ end
12
+
13
+ def store(obj)
14
+ synchronize{ @store << obj }
15
+ end
16
+
17
+ def each(descendant = true, &block)
18
+ store = synchronize{ @store.dup }
19
+ (descendant ? store.reverse : store).each(&block)
20
+ end
21
+
22
+ def size
23
+ synchronize{ @store.size }
24
+ end
25
+
26
+ def clear!
27
+ @store.clear
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stumb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - moro
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-09 00:00:00 +09:00
12
+ date: 2009-11-10 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -36,7 +36,7 @@ files:
36
36
  - lib/stumb/sheet.html.haml
37
37
  - lib/stumb/stamp.rb
38
38
  - lib/stumb/stamp_sheet.rb
39
- - lib/stumb/stub.rb
39
+ - lib/stumb/store.rb
40
40
  - lib/stumb.rb
41
41
  has_rdoc: true
42
42
  homepage: http://github.com/moro/stumb/
@@ -1,17 +0,0 @@
1
- require 'rack'
2
- require 'stumb/stamp'
3
-
4
- module Stumb
5
- class Stub
6
- attr_reader :stamps
7
- def initialize(*stub_response)
8
- @stamps = []
9
- @stub_response = stub_response
10
- end
11
-
12
- def call(env)
13
- @stamps << Stamp.new(Rack::Request.new(env))
14
- @stub_response
15
- end
16
- end
17
- end