Class: OodAppkit::FilesUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_appkit/files_url.rb

Overview

A class used to handle URLs for the system Files app.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: '', base_url: '/', fs_url: '/fs', api_url: '/api/v1/fs', template: '{/url*}{+path}') ⇒ FilesUrl

Returns a new instance of FilesUrl.

Parameters:

  • title (String) (defaults to: '')

    the title of the URL

  • base_url (String) (defaults to: '/')

    the base URL used to access this app

  • fs_url (String) (defaults to: '/fs')

    the URL used to request a filesystem view in the app

  • api_url (String) (defaults to: '/api/v1/fs')

    the URL used to request the app’s api

  • template (String) (defaults to: '{/url*}{+path}')

    the template used to generate URLs for this app

See Also:



14
15
16
17
18
19
20
21
22
# File 'lib/ood_appkit/files_url.rb', line 14

def initialize(title: '', base_url: '/', fs_url: '/fs', api_url: '/api/v1/fs', template: '{/url*}{+path}')
  @title = title
  @template = Addressable::Template.new template

  # Break up into arrays of strings
  @base_url = base_url.split('/').reject(&:empty?)
  @fs_url   = fs_url.split('/').reject(&:empty?)
  @api_url  = api_url.split('/').reject(&:empty?)
end

Instance Attribute Details

#titleString (readonly)

The title for this URL

Returns:

  • (String)

    the title of the URL



6
7
8
# File 'lib/ood_appkit/files_url.rb', line 6

def title
  @title
end

Instance Method Details

#api(path: '') ⇒ Addressable::URI

URL to access this app’s API for a given absolute file path

Parameters:

  • path (String, #to_s) (defaults to: '')

    the absolute path to the file on the filesystem

Returns:

  • (Addressable::URI)

    absolute url to access path in files app api



34
35
36
# File 'lib/ood_appkit/files_url.rb', line 34

def api(path: '')
  @template.expand url: @base_url + @api_url, path: path.to_s
end

#url(path: '') ⇒ Addressable::URI

URL to access this app for a given absolute file path

Parameters:

  • path (String, #to_s) (defaults to: '')

    the absolute path to the file on the filesystem

Returns:

  • (Addressable::URI)

    absolute url to access path in files app



27
28
29
# File 'lib/ood_appkit/files_url.rb', line 27

def url(path: '')
  @template.expand url: @base_url + @fs_url, path: path.to_s
end