Class: Webspicy::Resource
- Inherits:
-
Object
- Object
- Webspicy::Resource
- 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
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw, location = nil) ⇒ Resource
constructor
A new instance of Resource.
- #instantiate_url(params) ⇒ Object
- #locate(relative_path) ⇒ Object
- #located_at!(location) ⇒ Object
- #services ⇒ Object
- #to_info ⇒ Object
- #url ⇒ Object
- #url_placeholders ⇒ Object
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 |
Class Method Details
.info(raw) ⇒ Object
10 11 12 |
# File 'lib/webspicy/resource.rb', line 10 def self.info(raw) new(raw) end |
Instance Method Details
#instantiate_url(params) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/webspicy/resource.rb', line 36 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
18 19 20 21 22 |
# File 'lib/webspicy/resource.rb', line 18 def locate(relative_path) file = @location.parent/relative_path raise "File not found: #{file}" unless file.exists? file end |
#located_at!(location) ⇒ Object
14 15 16 |
# File 'lib/webspicy/resource.rb', line 14 def located_at!(location) @location = Path(location) end |
#services ⇒ Object
28 29 30 |
# File 'lib/webspicy/resource.rb', line 28 def services @raw[:services] end |
#to_info ⇒ Object
45 46 47 |
# File 'lib/webspicy/resource.rb', line 45 def to_info @raw end |
#url ⇒ Object
24 25 26 |
# File 'lib/webspicy/resource.rb', line 24 def url @raw[:url] end |
#url_placeholders ⇒ Object
32 33 34 |
# File 'lib/webspicy/resource.rb', line 32 def url_placeholders url.scan(/\{([a-zA-Z]+(\.[a-zA-Z]+)*)\}/).map{|x| x.first } end |