Class: Webspicy::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/webspicy/resource.rb,
lib/webspicy/resource/service.rb,
lib/webspicy/resource/service/test_case.rb,
lib/webspicy/resource/service/invocation.rb

Defined Under Namespace

Classes: Service

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, location = nil) ⇒ Resource

Returns a new instance of Resource.



4
5
6
7
8
# File 'lib/webspicy/resource.rb', line 4

def initialize(raw, location = nil)
  @raw = raw
  @location = location
  bind_services
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/webspicy/resource.rb', line 9

def location
  @location
end

Class Method Details

.info(raw) ⇒ Object



11
12
13
# File 'lib/webspicy/resource.rb', line 11

def self.info(raw)
  new(raw)
end

Instance Method Details

#instantiate_url(params) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/webspicy/resource.rb', line 37

def instantiate_url(params)
  url, rest = self.url, params.dup
  url_placeholders.each do |placeholder|
    value, rest = extract_placeholder_value(rest, placeholder)
    url = url.gsub("{#{placeholder}}", value.to_s)
  end
  [ url, rest ]
end

#locate(relative_path) ⇒ Object



19
20
21
22
23
# File 'lib/webspicy/resource.rb', line 19

def locate(relative_path)
  file = @location.parent/relative_path
  raise "File not found: #{file}" unless file.exists?
  file
end

#located_at!(location) ⇒ Object



15
16
17
# File 'lib/webspicy/resource.rb', line 15

def located_at!(location)
  @location = Path(location)
end

#servicesObject



29
30
31
# File 'lib/webspicy/resource.rb', line 29

def services
  @raw[:services]
end

#to_infoObject



46
47
48
# File 'lib/webspicy/resource.rb', line 46

def to_info
  @raw
end

#urlObject



25
26
27
# File 'lib/webspicy/resource.rb', line 25

def url
  @raw[:url]
end

#url_placeholdersObject



33
34
35
# File 'lib/webspicy/resource.rb', line 33

def url_placeholders
  url.scan(/\{([a-zA-Z]+(\.[a-zA-Z]+)*)\}/).map{|x| x.first }
end