david 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.travis.yml +2 -2
  4. data/Gemfile +8 -2
  5. data/Gemfile.lock +84 -44
  6. data/README.md +87 -5
  7. data/benchmarks/Gemfile +1 -0
  8. data/benchmarks/Gemfile.lock +3 -1
  9. data/benchmarks/coapbench.sh +20 -0
  10. data/benchmarks/quick.sh +2 -0
  11. data/benchmarks/rackup/Gemfile +10 -0
  12. data/benchmarks/rackup/Gemfile.lock +159 -0
  13. data/benchmarks/rackup/grape.ru +18 -0
  14. data/benchmarks/rackup/rack.ru +7 -0
  15. data/benchmarks/rackup/rails.ru +14 -0
  16. data/benchmarks/rps.rb +14 -2
  17. data/benchmarks/stress.sh +17 -0
  18. data/david.gemspec +0 -3
  19. data/experiments/Gemfile +6 -0
  20. data/experiments/concurrency/Gemfile +3 -0
  21. data/experiments/concurrency/stub.rb +88 -0
  22. data/experiments/hash_key.rb +64 -0
  23. data/experiments/string_concat.rb +21 -0
  24. data/experiments/symbol_to_proc.rb +15 -0
  25. data/experiments/thread_safe.rb +40 -0
  26. data/lib/david.rb +8 -4
  27. data/lib/david/actor.rb +1 -11
  28. data/lib/david/app_config.rb +112 -0
  29. data/lib/david/exchange.rb +124 -0
  30. data/lib/david/fake_logger.rb +11 -0
  31. data/lib/david/garbage_collector.rb +9 -17
  32. data/lib/david/guerilla/rack/utils.rb +18 -0
  33. data/lib/david/interop.rb +4 -0
  34. data/lib/david/interop/mandatory_etsi.rb +4 -0
  35. data/lib/david/interop/mandatory_etsi/grape.rb +37 -0
  36. data/lib/david/interop/mandatory_etsi/hobbit.rb +30 -0
  37. data/lib/david/interop/mandatory_etsi/nyny.rb +36 -0
  38. data/lib/david/interop/mandatory_etsi/rack.rb +26 -0
  39. data/lib/david/interop/mandatory_etsi/sinatra.rb +36 -0
  40. data/lib/david/observe.rb +24 -29
  41. data/lib/david/rails/action_controller/base.rb +9 -7
  42. data/lib/david/railties/config.rb +4 -4
  43. data/lib/david/registry.rb +22 -0
  44. data/lib/david/server.rb +56 -56
  45. data/lib/david/server/constants.rb +1 -0
  46. data/lib/david/server/mapping.rb +43 -11
  47. data/lib/david/server/mid_cache.rb +29 -0
  48. data/lib/david/server/multicast.rb +7 -5
  49. data/lib/david/server/respond.rb +53 -43
  50. data/lib/david/server/utility.rb +2 -1
  51. data/lib/david/show_exceptions.rb +12 -8
  52. data/lib/david/transmitter.rb +44 -0
  53. data/lib/david/trap.rb +10 -0
  54. data/lib/david/version.rb +1 -1
  55. data/lib/rack/handler/david.rb +6 -10
  56. data/lib/rack/hello_world.rb +25 -0
  57. data/spec/app_config_spec.rb +56 -0
  58. data/spec/dummy/app/controllers/etsis_controller.rb +26 -0
  59. data/spec/dummy/app/controllers/tests_controller.rb +9 -0
  60. data/spec/dummy/config/application.rb +4 -6
  61. data/spec/dummy/config/environments/development.rb +2 -2
  62. data/spec/dummy/config/environments/test.rb +2 -2
  63. data/spec/dummy/config/routes.rb +13 -53
  64. data/spec/interop/mandatory_spec.rb +100 -0
  65. data/spec/observe_spec.rb +8 -7
  66. data/spec/resource_discovery_spec.rb +3 -3
  67. data/spec/server_spec.rb +60 -15
  68. data/spec/spec_helper.rb +21 -2
  69. metadata +40 -33
  70. data/lib/david/request.rb +0 -80
  71. data/lib/david/server/deduplication.rb +0 -21
  72. data/lib/david/server/options.rb +0 -79
@@ -1,79 +0,0 @@
1
- module David
2
- class Server
3
- module Options
4
- protected
5
-
6
- def choose(name, value)
7
- send(('choose_' + name.to_s).to_sym, value)
8
- end
9
-
10
- def choose_block(value)
11
- default_to_true(:block, value)
12
- end
13
-
14
- def choose_cbor(value)
15
- if value.nil? && defined? Rails
16
- value = Rails.application.config.coap.cbor
17
- end
18
-
19
- !!value
20
- end
21
-
22
- def choose_default_format(value)
23
- if value.nil? && defined? Rails
24
- value = Rails.application.config.coap.default_format
25
- end
26
-
27
- value.nil? ? 'application/json' : value
28
- end
29
-
30
- # Rails starts on 'localhost' since 4.2.0.beta1
31
- # (Resolv class seems not to consider /etc/hosts)
32
- def choose_host(value)
33
- Socket::getaddrinfo(value, nil, nil, Socket::SOCK_STREAM)[0][3]
34
- end
35
-
36
- def choose_logger(log)
37
- fd = $stderr
38
- level = ::Logger::INFO
39
-
40
- case log
41
- when 'debug'
42
- level = ::Logger::DEBUG
43
- when 'none'
44
- fd = File.open('/dev/null', 'w')
45
- end
46
-
47
- logger = ::Logger.new(fd)
48
- logger.level = level
49
- logger.formatter = proc do |sev, time, prog, msg|
50
- "#{time.strftime('[%Y-%m-%d %H:%M:%S]')} #{sev} #{msg}\n"
51
- end
52
-
53
- Celluloid.logger = logger
54
-
55
- logger
56
- end
57
-
58
- def choose_mcast(value)
59
- default_to_true(:multicast, value)
60
- end
61
-
62
- def choose_observe(value)
63
- default_to_true(:observe, value)
64
- end
65
-
66
- def default_to_true(key, value)
67
- if value.nil? && defined? Rails
68
- value = Rails.application.config.coap.send(key)
69
- end
70
-
71
- return true if value.nil? || value.to_s == 'true'
72
-
73
- false
74
- end
75
-
76
- module_function :default_to_true
77
- end
78
- end
79
- end