mock_server 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,5 +65,21 @@ module MockServer
65
65
  }
66
66
  end
67
67
 
68
+ def load_data
69
+ FileUtils.mkdir_p(@options[:path]) unless File.exists? @options[:path]
70
+
71
+ data = []
72
+
73
+ @options[:record_filenames].map do |filename|
74
+ file_path = File.join( @options[:path], filename + '.yml' )
75
+ content = File.open(file_path).read
76
+ compiled = ERB.new(content).result
77
+ parsed = YAML.load(compiled)
78
+ data += parsed
79
+ end
80
+
81
+ data
82
+ end
83
+
68
84
  end
69
85
  end
@@ -38,5 +38,27 @@ module MockServer
38
38
  save_data(@data)
39
39
  end
40
40
 
41
+ def records_path
42
+ File.join( @options[:path], @options[:filename] + '.yml' )
43
+ end
44
+
45
+ def save_data(data)
46
+ File.open(records_path, 'w') do |f|
47
+ YAML.dump(data, f)
48
+ end
49
+ end
50
+
51
+ def load_data
52
+ FileUtils.mkdir_p(@options[:path]) unless File.exists? @options[:path]
53
+
54
+ data = YAML.load_file(records_path) rescue []
55
+
56
+ if data.is_a? Array
57
+ data
58
+ else
59
+ []
60
+ end
61
+ end
62
+
41
63
  end
42
64
  end
@@ -62,8 +62,13 @@ module MockServer
62
62
  end
63
63
 
64
64
  # Configuration
65
- def mock_server_use_record(filename)
66
- mock_server_config_set(:filename, filename)
65
+ def mock_server_use_record(*arguments)
66
+ mock_server_config_set(:record_filenames, arguments)
67
+ end
68
+
69
+ def mock_server_add_record(*arguments)
70
+ config = (mock_server_config_get(:record_filenames) || []) + arguments
71
+ mock_server_config_set(:record_filenames, config)
67
72
  end
68
73
 
69
74
  def mock_server_set_fixture_path(path)
@@ -150,6 +155,11 @@ module MockServer
150
155
  $mock_server_options[key] = value
151
156
  end
152
157
 
158
+ def mock_server_config_get(key)
159
+ $mock_server_options ||= {}
160
+ $mock_server_options[key]
161
+ end
162
+
153
163
  # Matchers helpers
154
164
  def mock_server_request(method, path, matcher)
155
165
  add_mock_server_matcher({ :method => method, :path => path, :matcher => matcher })
@@ -44,29 +44,5 @@ module MockServer
44
44
  :body => body
45
45
  }
46
46
  end
47
-
48
- # File utils
49
- def records_path
50
- File.join( @options[:path], @options[:filename] + '.yml' )
51
- end
52
-
53
- def load_data
54
- FileUtils.mkdir_p(@options[:path]) unless File.exists? @options[:path]
55
-
56
- data = YAML.load_file(records_path) rescue []
57
-
58
- if data.is_a? Array
59
- data
60
- else
61
- []
62
- end
63
- end
64
-
65
- def save_data(data)
66
- File.open(records_path, 'w') do |f|
67
- YAML.dump(data, f)
68
- end
69
- end
70
-
71
47
  end
72
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-04 00:00:00.000000000 Z
12
+ date: 2011-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &70292136050580 !ruby/object:Gem::Requirement
16
+ requirement: &70269520247400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70292136050580
24
+ version_requirements: *70269520247400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hashie
27
- requirement: &70292136049540 !ruby/object:Gem::Requirement
27
+ requirement: &70269520245200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70292136049540
35
+ version_requirements: *70269520245200
36
36
  description:
37
37
  email: unixcharles@gmail.com
38
38
  executables: []