cameleon 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/LICENSE.txt +1 -1
- data/README.md +16 -1
- data/VERSION +1 -1
- data/lib/cameleon/action.rb +45 -3
- metadata +23 -23
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTQxNDM0ZWRhMDMzMjEzNDlhNDk5MGRhYzEzNTgwNjg3N2ZkM2ZkYQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60f13a50c58163f9e4371856a863664fa0bcccac
|
4
|
+
data.tar.gz: 12983397d6e8c0bdf31510687d21efffd7fb2f6d
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OTg3ZTk3NTg4OGNmOTJmYTEyZjlmN2YxNDhkMTg0MmE3MGU0ZjgwNmY3YWQz
|
11
|
-
Nzc5YjVlODI1ZWYxNDYxYzAwYzBhZjI0M2IxOWQyN2RmNTgwOWI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
OWY4ZWI1NTQ2OGI1ZjQwNDU4MWY2ZmNkYzVkYzM0NDExMGZmMGZmNGMyYTRm
|
14
|
-
YzBhODBjOTg0YWFhNzI5Mjg5MGY2YTgwMjhlYTdkOWNiNWRlMDFkOWM5YzA4
|
15
|
-
Y2YwNTM1YTNmMTY4MDIxNjEyY2Y4NGIzZjFhNzZhMGMxMmE5YjU=
|
6
|
+
metadata.gz: ebb0ab435472008c3dfbad172b88912bf361f45ebf6bbd9fa0d99ef129e2eac8cc0a0a18ab0a34f573bcf8d91a99b39137e9c3325978fc833bf6fc1a140b36c3
|
7
|
+
data.tar.gz: deca055d5b4f11a99b6e98437a2eec13f33ceb9c9bd065076eb2b947e6d5441b59d93b8f48f1417dee27089a9f556d40c5c52fbeee82f0d6813bab3b2b3c9b51
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -88,6 +88,21 @@ Below shows a sample of "_switch.rb".
|
|
88
88
|
|
89
89
|
# if else, render "default" (any extention acceptable) file.
|
90
90
|
|
91
|
+
### RESTful URI
|
92
|
+
Cameleon supports RESTful URI such as:
|
93
|
+
|
94
|
+
http://localhost:9292/resource/${category_name}/${id}
|
95
|
+
|
96
|
+
If you want to use such URI, create directory as below.
|
97
|
+
|
98
|
+
response/resource/$category_name/$id
|
99
|
+
|
100
|
+
Directory that name start with '$' is placeholder of the URI.
|
101
|
+
If directory name is '$category_name/$id' and URI 'fiction/12',
|
102
|
+
'fiction' and '12' are mapped into params['category_name'] and params['id'].
|
103
|
+
Then in your _switch.rb or response(erb) file,
|
104
|
+
you can use params['category_name'] and params['id'] they are specified by URI.
|
105
|
+
|
91
106
|
### Validation
|
92
107
|
Cameleon can validate HTTP request body. Currently JSON format is supported. If you want to validate your request to Cameleon, add 'validation' attribute and 'type' sub-attribute as 'json' into your 'cameleon.yml' config file.
|
93
108
|
|
@@ -131,7 +146,7 @@ Cameleon is released under the MIT license.
|
|
131
146
|
|
132
147
|
|
133
148
|
## Copyright
|
134
|
-
Copyright (c) 2011 [daisuke sugimori][1] ([@daixque][2]).
|
149
|
+
Copyright (c) 2011 - 2014 [daisuke sugimori][1] ([@daixque][2]).
|
135
150
|
|
136
151
|
[1]: http://opentechnica.blogspot.com/
|
137
152
|
[2]: http://twitter.com/daixque
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/cameleon/action.rb
CHANGED
@@ -13,6 +13,10 @@ class Cameleon
|
|
13
13
|
def find_default_file
|
14
14
|
Dir.entries(@base_path).find { |f| f =~ /^default\./ }
|
15
15
|
end
|
16
|
+
|
17
|
+
def switch_filepath
|
18
|
+
File.join @base_path, "_switch.rb"
|
19
|
+
end
|
16
20
|
|
17
21
|
def handle(req)
|
18
22
|
@base_path = File.join("response", req.path)
|
@@ -28,11 +32,15 @@ class Cameleon
|
|
28
32
|
return [400, {}, [e.message]]
|
29
33
|
end
|
30
34
|
end
|
31
|
-
switch_filepath = File.join @base_path, "_switch.rb"
|
32
35
|
renderer = nil
|
33
36
|
if !File.exists?(@base_path)
|
34
|
-
|
35
|
-
|
37
|
+
if placeholder_dir = on_placeholder_dir("response", req.path)
|
38
|
+
@base_path = placeholder_dir
|
39
|
+
else
|
40
|
+
return [404, {}, ["dir not found: #{@base_path}"]]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
if File.exists?(switch_filepath)
|
36
44
|
renderer = Renderer.run_switch(@base_path, req, switch_filepath)
|
37
45
|
else
|
38
46
|
renderer = Renderer.render_file(@base_path, req)
|
@@ -40,6 +48,40 @@ class Cameleon
|
|
40
48
|
renderer.build_response
|
41
49
|
end
|
42
50
|
|
51
|
+
def on_placeholder_dir(base_dir_path, target_dir_path, found = false)
|
52
|
+
if (!target_dir_path || target_dir_path == "")
|
53
|
+
if found
|
54
|
+
return base_dir_path
|
55
|
+
else
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
target_dir_path = target_dir_path.gsub(/^\//, '')
|
60
|
+
first_dir_name, *rest = target_dir_path.split('/')
|
61
|
+
first_dir_path = File.join(base_dir_path, first_dir_name)
|
62
|
+
if File.exists?(first_dir_path)
|
63
|
+
on_placeholder_dir(first_dir_path, rest.join('/'))
|
64
|
+
else
|
65
|
+
new_dir = search_placeholder_dir(base_dir_path, first_dir_name)
|
66
|
+
if new_dir
|
67
|
+
on_placeholder_dir(new_dir, rest.join('/'), true)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def search_placeholder_dir(base_dir_path, target_dir_name)
|
73
|
+
files = Dir.glob(File.join(base_dir_path, '*'))
|
74
|
+
# find directory start with $.
|
75
|
+
# if there are some directories start with $, use one that found first.
|
76
|
+
found = files.find_all{ |f| File.directory?(f) }.find{ |f| ret = f =~ /.*\$([a-zA-Z0-9]*)$/ }
|
77
|
+
if (found)
|
78
|
+
path_name = $1
|
79
|
+
@params[path_name] = target_dir_name
|
80
|
+
ret = File.join(base_dir_path, "$" + path_name)
|
81
|
+
ret
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
43
85
|
def validate_request_body
|
44
86
|
validation_type = Cameleon.config.validation && Cameleon.config.validation.type
|
45
87
|
case validation_type
|
metadata
CHANGED
@@ -1,139 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cameleon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- daixque
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: hashie
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: json-schema
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: nokogiri
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: bundler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: shoulda
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
description: Cameleon is HTTP mock server framework based on Rack. You can easily
|
@@ -202,17 +202,17 @@ require_paths:
|
|
202
202
|
- lib
|
203
203
|
required_ruby_version: !ruby/object:Gem::Requirement
|
204
204
|
requirements:
|
205
|
-
- -
|
205
|
+
- - '>='
|
206
206
|
- !ruby/object:Gem::Version
|
207
207
|
version: '0'
|
208
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
209
|
requirements:
|
210
|
-
- -
|
210
|
+
- - '>='
|
211
211
|
- !ruby/object:Gem::Version
|
212
212
|
version: '0'
|
213
213
|
requirements: []
|
214
214
|
rubyforge_project:
|
215
|
-
rubygems_version: 2.
|
215
|
+
rubygems_version: 2.0.3
|
216
216
|
signing_key:
|
217
217
|
specification_version: 4
|
218
218
|
summary: Cameleon is HTTP mock server framework.
|