Class: Webspicy::Scope
- Inherits:
-
Object
- Object
- Webspicy::Scope
- Defined in:
- lib/webspicy/scope.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#data_system ⇒ Object
Returns the Data system to use for parsing schemas.
- #each_counterexamples(service, &bl) ⇒ Object
- #each_example(service) ⇒ Object
- #each_generated_counterexamples(service, &bl) ⇒ Object
-
#each_resource(&bl) ⇒ Object
Yields each resource in the current scope in turn.
-
#each_resource_file(&bl) ⇒ Object
Yields each resource file in the current scope.
- #each_service(resource, &bl) ⇒ Object
- #each_testcase(service, &bl) ⇒ Object
-
#get_client ⇒ Object
Returns an instance of the client to use to invoke web services.
-
#initialize(config) ⇒ Scope
constructor
A new instance of Scope.
-
#parse_schema(fio) ⇒ Object
Parses a Finitio schema based on the data system.
- #postconditions ⇒ Object
- #preconditions ⇒ Object
-
#to_real_url(url, test_case = nil, &bl) ⇒ Object
Convert an instantiated URL found in a webservice definition to a real URL, using the configuration host.
Constructor Details
#initialize(config) ⇒ Scope
Returns a new instance of Scope.
4 5 6 |
# File 'lib/webspicy/scope.rb', line 4 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/webspicy/scope.rb', line 7 def config @config end |
Instance Method Details
#data_system ⇒ Object
Returns the Data system to use for parsing schemas
80 81 82 |
# File 'lib/webspicy/scope.rb', line 80 def data_system @data_system ||= config.data_system end |
#each_counterexamples(service, &bl) ⇒ Object
53 54 55 |
# File 'lib/webspicy/scope.rb', line 53 def each_counterexamples(service, &bl) service.counterexamples.each{|s| yield(s, true) } if config.run_counterexamples? end |
#each_example(service) ⇒ Object
49 50 51 |
# File 'lib/webspicy/scope.rb', line 49 def each_example(service) service.examples.each{|s| yield(s, false) } end |
#each_generated_counterexamples(service, &bl) ⇒ Object
57 58 59 60 61 |
# File 'lib/webspicy/scope.rb', line 57 def each_generated_counterexamples(service, &bl) Webspicy.with_scope(self) do service.generated_counterexamples.each{|s| yield(s, true) } end if config.run_counterexamples? end |
#each_resource(&bl) ⇒ Object
Yields each resource in the current scope in turn.
38 39 40 41 42 43 |
# File 'lib/webspicy/scope.rb', line 38 def each_resource(&bl) return enum_for(:each_resource) unless block_given? each_resource_file do |file, folder| yield Webspicy.resource(file.load, file, self) end end |
#each_resource_file(&bl) ⇒ Object
Yields each resource file in the current scope
22 23 24 25 |
# File 'lib/webspicy/scope.rb', line 22 def each_resource_file(&bl) return enum_for(:each_resource_file) unless block_given? _each_resource_file(config, &bl) end |
#each_service(resource, &bl) ⇒ Object
45 46 47 |
# File 'lib/webspicy/scope.rb', line 45 def each_service(resource, &bl) resource.services.select(&to_filter_proc(config.service_filter)).each(&bl) end |
#each_testcase(service, &bl) ⇒ Object
63 64 65 66 67 |
# File 'lib/webspicy/scope.rb', line 63 def each_testcase(service, &bl) each_example(service, &bl) each_counterexamples(service, &bl) each_generated_counterexamples(service, &bl) end |
#get_client ⇒ Object
Returns an instance of the client to use to invoke web services
91 92 93 |
# File 'lib/webspicy/scope.rb', line 91 def get_client config.client.new(self) end |
#parse_schema(fio) ⇒ Object
Parses a Finitio schema based on the data system.
75 76 77 |
# File 'lib/webspicy/scope.rb', line 75 def parse_schema(fio) data_system.parse(fio) end |
#postconditions ⇒ Object
13 14 15 |
# File 'lib/webspicy/scope.rb', line 13 def postconditions config.postconditions end |
#preconditions ⇒ Object
9 10 11 |
# File 'lib/webspicy/scope.rb', line 9 def preconditions config.preconditions end |
#to_real_url(url, test_case = nil, &bl) ⇒ Object
Convert an instantiated URL found in a webservice definition to a real URL, using the configuration host.
When no host resolved on the configuration and the url is not already an absolute URL, yields the block if given, or raise an exception.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/webspicy/scope.rb', line 101 def to_real_url(url, test_case = nil, &bl) case config.host when Proc config.host.call(url, test_case) when String url =~ /^http/ ? url : "#{config.host}#{url}" else return url if url =~ /^http/ return yield(url) if block_given? raise "Unable to resolve `#{url}` : no host resolver provided\nSee `Configuration#host=" end end |