Class: Acfs::Location Private

Inherits:
Object
  • Object
show all
Defined in:
lib/acfs/location.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Describes a URL with placeholders.

Constant Summary collapse

REGEXP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^:([A-z][A-z0-9_]*)$/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, vars = {}) ⇒ Location

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Location.



13
14
15
16
17
18
# File 'lib/acfs/location.rb', line 13

def initialize(uri, vars = {})
  @raw       = URI.parse uri
  @vars      = vars
  @struct    = raw.path.split('/').reject(&:empty?).map {|s| s =~ REGEXP ? Regexp.last_match[1].to_sym : s }
  @arguments = struct.select {|s| s.is_a?(Symbol) }
end

Instance Attribute Details

#argumentsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/acfs/location.rb', line 9

def arguments
  @arguments
end

#rawObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/acfs/location.rb', line 9

def raw
  @raw
end

#structObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/acfs/location.rb', line 9

def struct
  @struct
end

#varsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/acfs/location.rb', line 9

def vars
  @vars
end

Instance Method Details

#build(vars) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/acfs/location.rb', line 20

def build(vars)
  self.class.new raw.to_s, vars.stringify_keys.merge(self.vars)
end

#extract_from(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
# File 'lib/acfs/location.rb', line 24

def extract_from(*args)
  vars = {}
  arguments.each {|key| vars[key.to_s] = extract_arg(key, args) }

  build(vars)
end

#raw_uriObject Also known as: to_s

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'lib/acfs/location.rb', line 37

def raw_uri
  raw.to_s
end

#strObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
# File 'lib/acfs/location.rb', line 31

def str
  uri = raw.dup
  uri.path = "/#{struct.map {|s| lookup_variable(s) }.join('/')}"
  uri.to_s
end