-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep moving web specific behavior & classes under Web.
- Loading branch information
Showing
18 changed files
with
255 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module Webspicy | ||
module Web | ||
class Specification < Webspicy::Specification | ||
|
||
class << self | ||
def info(raw) | ||
new(raw) | ||
end | ||
|
||
def singleservice(raw) | ||
converted = { | ||
name: raw[:name] || "Unamed specification", | ||
url: raw[:url], | ||
services: [ | ||
Webspicy::Web.service(raw.reject{|k| k==:url or k==:name }, Webspicy.current_scope) | ||
] | ||
} | ||
info(converted) | ||
end | ||
end | ||
|
||
def url | ||
@raw[:url] | ||
end | ||
|
||
def url_pattern | ||
@url_pattern ||= Mustermann.new(url, type: :template) | ||
end | ||
|
||
def url_placeholders | ||
url.scan(/\{([a-zA-Z]+(\.[a-zA-Z]+)*)\}/).map{|x| x.first } | ||
end | ||
|
||
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 | ||
|
||
def to_singleservice | ||
raise NotImplementedError | ||
end | ||
|
||
private | ||
|
||
def extract_placeholder_value(params, placeholder, split = nil) | ||
return extract_placeholder_value(params, placeholder, placeholder.split(".")) unless split | ||
|
||
key = [ split.first, split.first.to_sym ].find{|k| params.has_key?(k) } | ||
raise "Missing URL parameter `#{placeholder}`" unless key | ||
|
||
if split.size == 1 | ||
[ params[key], params.dup.delete_if{|k| k == key } ] | ||
else | ||
value, rest = extract_placeholder_value(params[key], placeholder, split[1..-1]) | ||
[ value, params.merge(key => rest) ] | ||
end | ||
end | ||
|
||
end # class Specification | ||
end # module Web | ||
end # module Webspicy | ||
require_relative 'specification/service' | ||
require_relative 'specification/test_case' | ||
require_relative 'specification/file_upload' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Webspicy | ||
module Web | ||
class Specification | ||
class FileUpload | ||
|
||
def initialize(raw) | ||
@path = raw[:path] | ||
@content_type = raw[:content_type] | ||
@param_name = raw[:param_name] || "file" | ||
end | ||
|
||
attr_reader :path, :content_type, :param_name | ||
|
||
def self.info(raw) | ||
new(raw) | ||
end | ||
|
||
def locate(specification) | ||
FileUpload.new({ | ||
path: specification.locate(path), | ||
content_type: content_type | ||
}) | ||
end | ||
|
||
def to_info | ||
{ path: path.to_s, | ||
content_type: content_type, | ||
param_name: param_name } | ||
end | ||
|
||
def to_s | ||
"FileUpload(#{to_info})" | ||
end | ||
alias :inspect :to_s | ||
|
||
end # class FileUpload | ||
end # class Specification | ||
end # module Web | ||
end # module Webspicy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Webspicy | ||
module Web | ||
class Specification | ||
class Service < Webspicy::Specification::Service | ||
|
||
def method | ||
@raw[:method] | ||
end | ||
|
||
end # class Service | ||
end # class Specification | ||
end # module Web | ||
end # module Webspicy |
Oops, something went wrong.