Class: RubyEventStore::Browser::App
- Inherits:
-
Object
- Object
- RubyEventStore::Browser::App
- Defined in:
- lib/ruby_event_store/browser/app.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(event_store_locator:, related_streams_query:, host:, root_path:, api_url:) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(event_store_locator:, related_streams_query:, host:, root_path:, api_url:) ⇒ App
Returns a new instance of App.
59 60 61 62 63 |
# File 'lib/ruby_event_store/browser/app.rb', line 59 def initialize(event_store_locator:, related_streams_query:, host:, root_path:, api_url:) @event_store_locator = event_store_locator @related_streams_query = @routing = Urls.from_configuration(host, root_path, api_url) end |
Class Method Details
.for(event_store_locator:, host: nil, path: nil, api_url: nil, environment: nil, related_streams_query: DEFAULT_RELATED_STREAMS_QUERY) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruby_event_store/browser/app.rb', line 11 def self.for( event_store_locator:, host: nil, path: nil, api_url: nil, environment: nil, related_streams_query: DEFAULT_RELATED_STREAMS_QUERY ) warn(<<~WARN) if environment Passing :environment to RubyEventStore::Browser::App.for is deprecated. This option is no-op, has no effect and will be removed in next major release. WARN warn(<<~WARN) if host Passing :host to RubyEventStore::Browser::App.for is deprecated. This option will be removed in next major release. Host and mount points are correctly recognized from Rack environment and this option is redundant. WARN warn(<<~WARN) if path Passing :path to RubyEventStore::Browser::App.for is deprecated. This option will be removed in next major release. Host and mount points are correctly recognized from Rack environment and this option is redundant. WARN Rack::Builder.new do use Rack::Static, urls: { "/ruby_event_store_browser.js" => "ruby_event_store_browser.js", "/ruby_event_store_browser.css" => "ruby_event_store_browser.css", "/bootstrap.js" => "bootstrap.js" }, root: "#{__dir__}/../../../public" run App.new( event_store_locator: event_store_locator, related_streams_query: , host: host, root_path: path, api_url: api_url ) end end |
Instance Method Details
#call(env) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ruby_event_store/browser/app.rb', line 65 def call(env) router = Router.new(routing) router.add_route("GET", "/api/events/:event_id") do |params| json GetEvent.new(event_store: event_store, event_id: params.fetch("event_id")) end router.add_route("GET", "/api/streams/:stream_name") do |params, urls| json GetStream.new( stream_name: params.fetch("stream_name"), routing: urls, related_streams_query: ) end router.add_route("GET", "/api/streams/:stream_name/relationships/events") do |params, urls| json GetEventsFromStream.new( event_store: event_store, routing: urls, stream_name: params.fetch("stream_name"), page: params["page"] ) end %w[/ /events/:event_id /streams/:stream_name].each do |starting_route| router.add_route("GET", starting_route) do |_, urls| erb bootstrap_html, browser_js_src: urls.browser_js_url, browser_css_src: urls.browser_css_url, bootstrap_js_src: urls.bootstrap_js_url, initial_data: { rootUrl: urls.app_url, apiUrl: urls.api_url, resVersion: res_version } end end router.handle(Rack::Request.new(env)) rescue EventNotFound, Router::NoMatch not_found end |