Class: LeanCloud::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/lean_cloud/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, match = false, &block) ⇒ Route

Returns a new instance of Route.



4
5
6
7
8
9
10
11
# File 'lib/lean_cloud/route.rb', line 4

def initialize(name, options, match=false, &block)
  options[:on] ||= :collection
  @name     = name
  @request  = options[:via] ||= :get
  @match    = match
  @options  = options
  @block    = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/lean_cloud/route.rb', line 3

def block
  @block
end

#matchObject

Returns the value of attribute match.



3
4
5
# File 'lib/lean_cloud/route.rb', line 3

def match
  @match
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/lean_cloud/route.rb', line 3

def name
  @name
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/lean_cloud/route.rb', line 3

def options
  @options
end

#requestObject

Returns the value of attribute request.



3
4
5
# File 'lib/lean_cloud/route.rb', line 3

def request
  @request
end

Instance Method Details

#url(*args) ⇒ Object



13
14
15
16
17
18
# File 'lib/lean_cloud/route.rb', line 13

def url(*args)
  namespace = options[:namespace] if !options[:unscope]
  id = args.shift                 if options[:on].to_sym == :member
  path = !match ? name.to_s : match.sub(/(:\w+)/, args[0].to_s) if !options[:root]
  [namespace, id, path].compact.join('/')
end