Class: RubyEventStore::Browser::Urls

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/browser/urls.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, root_path) ⇒ Urls

Returns a new instance of Urls.



20
21
22
23
24
# File 'lib/ruby_event_store/browser/urls.rb', line 20

def initialize(host, root_path)
  @host = host
  @root_path = root_path
  @app_url = [host, root_path].compact.reduce(:+)
end

Instance Attribute Details

#app_urlObject (readonly)

Returns the value of attribute app_url.



18
19
20
# File 'lib/ruby_event_store/browser/urls.rb', line 18

def app_url
  @app_url
end

#hostObject (readonly)

Returns the value of attribute host.



18
19
20
# File 'lib/ruby_event_store/browser/urls.rb', line 18

def host
  @host
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



18
19
20
# File 'lib/ruby_event_store/browser/urls.rb', line 18

def root_path
  @root_path
end

Class Method Details

.from_configuration(host, root_path) ⇒ Object



6
7
8
# File 'lib/ruby_event_store/browser/urls.rb', line 6

def self.from_configuration(host, root_path)
  new(host, root_path)
end

.initialObject



10
11
12
# File 'lib/ruby_event_store/browser/urls.rb', line 10

def self.initial
  new(nil, nil)
end

Instance Method Details

#==(other) ⇒ Object



63
64
65
# File 'lib/ruby_event_store/browser/urls.rb', line 63

def ==(other)
  self.class.eql?(other.class) && app_url.eql?(other.app_url)
end

#app_url_for(*segments, query: nil) ⇒ Object



50
51
52
53
# File 'lib/ruby_event_store/browser/urls.rb', line 50

def app_url_for(*segments, query: nil)
  path = segments.map { |segment| Rack::Utils.escape(segment) }.join("/")
  query ? "#{app_url}/#{path}?#{URI.encode_www_form(query)}" : "#{app_url}/#{path}"
end

#browser_css_urlObject



59
60
61
# File 'lib/ruby_event_store/browser/urls.rb', line 59

def browser_css_url
  "#{app_url}/#{BROWSER_CSS}"
end

#browser_js_urlObject



55
56
57
# File 'lib/ruby_event_store/browser/urls.rb', line 55

def browser_js_url
  "#{app_url}/#{BROWSER_JS}"
end

#event_url(event_id) ⇒ Object



30
31
32
# File 'lib/ruby_event_store/browser/urls.rb', line 30

def event_url(event_id)
  "#{app_url}/events/#{event_id}"
end

#stream_page_url(stream_name, cursor, count) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ruby_event_store/browser/urls.rb', line 34

def stream_page_url(stream_name, cursor, count)
  query =
    URI.encode_www_form(
      [["page[position]", cursor[:position]], ["page[direction]", cursor[:direction]], ["page[count]", count]],
    )
  "#{stream_url(stream_name)}?#{query}"
end

#stream_url(stream_name) ⇒ Object



26
27
28
# File 'lib/ruby_event_store/browser/urls.rb', line 26

def stream_url(stream_name)
  "#{app_url}/streams/#{Rack::Utils.escape(stream_name)}"
end

#swimlane_more_url(stream_names, cursor, sort) ⇒ Object



46
47
48
# File 'lib/ruby_event_store/browser/urls.rb', line 46

def swimlane_more_url(stream_names, cursor, sort)
  "#{app_url}/swimlane/more?#{swimlane_query(stream_names, sort, [["cursor", cursor]])}"
end

#swimlane_url(stream_names, sort = nil) ⇒ Object



42
43
44
# File 'lib/ruby_event_store/browser/urls.rb', line 42

def swimlane_url(stream_names, sort = nil)
  "#{app_url}/swimlane?#{swimlane_query(stream_names, sort)}"
end

#with_request(request) ⇒ Object



14
15
16
# File 'lib/ruby_event_store/browser/urls.rb', line 14

def with_request(request)
  Urls.new(host || request.base_url, root_path || request.script_name)
end