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, api_url) ⇒ Urls

Returns a new instance of Urls.



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

def initialize(host, root_path, api_url)
  @host = host
  @root_path = root_path
  @app_url = [host, root_path].compact.reduce(:+)
  @api_url = api_url || ("#{app_url}/api" if app_url)
  @gem_source = GemSource.new($LOAD_PATH)
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



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

def api_url
  @api_url
end

#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, api_url = nil) ⇒ Object



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

def self.from_configuration(host, root_path, api_url = nil)
  new(host, root_path, api_url)
end

.initialObject



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

def self.initial
  new(nil, nil, nil)
end

Instance Method Details

#==(o) ⇒ Object



72
73
74
# File 'lib/ruby_event_store/browser/urls.rb', line 72

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

#bootstrap_js_urlObject



68
69
70
# File 'lib/ruby_event_store/browser/urls.rb', line 68

def bootstrap_js_url
  "#{app_url}/bootstrap.js"
end

#browser_css_urlObject



59
60
61
62
63
64
65
66
# File 'lib/ruby_event_store/browser/urls.rb', line 59

def browser_css_url
  name = "ruby_event_store_browser.css"
  if gem_source.from_git?
    cdn_file_url(name)
  else
    local_file_url(name)
  end
end

#browser_js_urlObject



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

def browser_js_url
  name = "ruby_event_store_browser.js"
  if gem_source.from_git?
    cdn_file_url(name)
  else
    local_file_url(name)
  end
end

#events_urlObject



28
29
30
# File 'lib/ruby_event_store/browser/urls.rb', line 28

def events_url
  "#{api_url}/events"
end

#paginated_events_from_stream_url(id:, position: nil, direction: nil, count: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_event_store/browser/urls.rb', line 36

def paginated_events_from_stream_url(id:, position: nil, direction: nil, count: nil)
  stream_name = Rack::Utils.escape(id)
  query_string =
    URI.encode_www_form(
      { "page[position]" => position, "page[direction]" => direction, "page[count]" => count }.compact
    )

  if query_string.empty?
    "#{api_url}/streams/#{stream_name}/relationships/events"
  else
    "#{api_url}/streams/#{stream_name}/relationships/events?#{query_string}"
  end
end

#streams_urlObject



32
33
34
# File 'lib/ruby_event_store/browser/urls.rb', line 32

def streams_url
  "#{api_url}/streams"
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, api_url)
end