doppelserver 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +10 -9
- data/.rubocop.yml +1 -1
- data/README.md +17 -1
- data/Rakefile +3 -0
- data/lib/doppelserver/base_server.rb +65 -0
- data/lib/doppelserver/data.rb +33 -0
- data/lib/doppelserver/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8ecd7f77f59921d42f9f6b3dc9a49f6209c4f315aa0325c8e6b266e58fa6f26
|
4
|
+
data.tar.gz: fe58b716b71ab2e73ae34441f020e850090f174952995daa6204f6e24801ea2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e74ec8e4724ad41eae0b1eef6f95abcfd500efd2656c72a92c64f11ec2ceb824e2112860d6e4ab8b8f1cde9e9105ec920546fbd4f08b6554101c2adec2e2f2f8
|
7
|
+
data.tar.gz: e4cf2ac4da81bd7af95cba53de81a1bfa6e2bc92f184ae5e75b65748a7ad13e93d004adf7f9ca986e2c369206f4e32ee729f775044a2a0850cbfd832d4d41a64
|
data/.gitignore
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
/.bundle/
|
2
|
-
|
3
|
-
|
4
|
-
/
|
5
|
-
/
|
6
|
-
/
|
7
|
-
/
|
8
|
-
/
|
9
|
-
/
|
1
|
+
/.bundle/
|
2
|
+
/*.gem
|
3
|
+
/.yardoc
|
4
|
+
/Gemfile.lock
|
5
|
+
/_yardoc/
|
6
|
+
/coverage/
|
7
|
+
/doc/
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/tmp/
|
data/.rubocop.yml
CHANGED
@@ -8,7 +8,7 @@ require: rubocop-rspec
|
|
8
8
|
# That last one's my doing but I only get the spew when my gem is here, too.
|
9
9
|
# Searching the web they're all more likely rubocop-rspec's fault than my code.
|
10
10
|
# So I'll leave this as is and look into it later. TODO: Look into it.
|
11
|
-
require: drewcoo-cops
|
11
|
+
# require: drewcoo-cops
|
12
12
|
|
13
13
|
AllCops:
|
14
14
|
DefaultFormatter: progress
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[](https://circleci.com/gh/drewcoo/doppelserver)
|
5
5
|
[](https://coveralls.io/github/drewcoo/doppelserver?branch=master)
|
6
6
|
[](https://badge.fury.io/rb/doppelserver)
|
7
|
+
[](https://www.codacy.com/app/drewcoo/doppelserver?utm_source=github.com&utm_medium=referral&utm_content=drewcoo/doppelserver&utm_campaign=Badge_Grade)
|
7
8
|
|
8
9
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/doppelserver`. To experiment with that code, run `bin/console` for an interactive prompt.
|
9
10
|
|
@@ -37,7 +38,22 @@ Or install it yourself as:
|
|
37
38
|
|
38
39
|
## Usage
|
39
40
|
|
40
|
-
|
41
|
+
Scenarios this should cover:
|
42
|
+
* Fake a server from your (integration) tests
|
43
|
+
* Default behaviors
|
44
|
+
* Imagine a really stupid CRUD database backing the test server,
|
45
|
+
one that auto-created schema as it went. That's pretty much it.
|
46
|
+
How? Easy. Instead of a db it's just a hash in memory. Dumb? Yup.
|
47
|
+
* Overrides
|
48
|
+
* Control endpoints
|
49
|
+
* Run interactively (irb/pry console?) while debugging your code
|
50
|
+
* Record endpoint usage?
|
51
|
+
* Types of service:
|
52
|
+
* REST-ish
|
53
|
+
* GraphQL
|
54
|
+
* Others? (WSDL?)
|
55
|
+
* Client bindings? Not sure that makes sense unless it's POROs or x-language.
|
56
|
+
|
41
57
|
|
42
58
|
## Development
|
43
59
|
|
data/Rakefile
CHANGED
@@ -8,27 +8,63 @@ module Doppelserver
|
|
8
8
|
|
9
9
|
class BaseServer < Sinatra::Base
|
10
10
|
require 'active_support' # for singularization/pluralization
|
11
|
+
|
12
|
+
#
|
13
|
+
# Determines if
|
14
|
+
# word:: an input word
|
15
|
+
# is singular.
|
16
|
+
# Retutns truthy.
|
17
|
+
#
|
11
18
|
def singular?(word)
|
12
19
|
ActiveSupport::Inflector.singularize(word) == word
|
13
20
|
end
|
14
21
|
|
22
|
+
#
|
23
|
+
# If ENFORCE_PLURALS is true (default == true)
|
24
|
+
# This enforces plural names for all collections
|
25
|
+
# and returns 403 otherwise.
|
26
|
+
# word:: collection name
|
27
|
+
#
|
15
28
|
def enforce_plural(word)
|
16
29
|
return unless ENFORCE_PLURALS
|
17
30
|
halt 403, 'only plural collection names allowed' if singular?(word)
|
18
31
|
end
|
19
32
|
|
33
|
+
#
|
34
|
+
# Hold all of the data internally in the @@data.
|
35
|
+
# It's the Data class, which holds a hash of data and
|
36
|
+
# another of next keys. (???)
|
37
|
+
#
|
20
38
|
configure do
|
21
39
|
@@data = Data.new
|
22
40
|
end
|
23
41
|
|
42
|
+
#
|
43
|
+
# All meta-operations should happen through a /control endpoint.
|
44
|
+
#
|
45
|
+
# Deletes the internal data by clearing the @@data hash.
|
46
|
+
#
|
24
47
|
delete '/control/data' do
|
25
48
|
@@data.clear
|
26
49
|
end
|
27
50
|
|
51
|
+
#
|
52
|
+
# TODO:: Define this.
|
53
|
+
# Maybe make it a list of collections?
|
54
|
+
# Or all collections with all their data?
|
55
|
+
#
|
56
|
+
# For now, it returns a placeholder string.
|
57
|
+
#
|
28
58
|
get '/' do
|
29
59
|
'here i am' # TODO: Change this.
|
30
60
|
end
|
31
61
|
|
62
|
+
#
|
63
|
+
# Gets the data at:
|
64
|
+
# endpoint:: the collection
|
65
|
+
# id:: the instance identifier
|
66
|
+
# Or 404s when not found.
|
67
|
+
#
|
32
68
|
get '/:endpoint/:id' do
|
33
69
|
collection, id = params['endpoint'], params['id']
|
34
70
|
enforce_plural(collection)
|
@@ -38,6 +74,12 @@ module Doppelserver
|
|
38
74
|
json(result)
|
39
75
|
end
|
40
76
|
|
77
|
+
#
|
78
|
+
# Returns the data at:
|
79
|
+
# endpoint:: collection name
|
80
|
+
# This is all of the data in that collection
|
81
|
+
# or 404 if no endpoint.
|
82
|
+
#
|
41
83
|
get '/:endpoint' do
|
42
84
|
collection = params[:endpoint]
|
43
85
|
enforce_plural(collection)
|
@@ -45,6 +87,14 @@ module Doppelserver
|
|
45
87
|
json(@@data.get_collection(collection))
|
46
88
|
end
|
47
89
|
|
90
|
+
#
|
91
|
+
# No PUT, POST.
|
92
|
+
# Adds data to collection:
|
93
|
+
# endpoint:: is the name of the collection.
|
94
|
+
# If it doesn't exist, add new collection.
|
95
|
+
# If it does exist replaces (???) data.
|
96
|
+
# Also 403 on no data passed.
|
97
|
+
#
|
48
98
|
post '/:endpoint' do
|
49
99
|
request.body.rewind
|
50
100
|
collection = params['endpoint']
|
@@ -59,6 +109,15 @@ module Doppelserver
|
|
59
109
|
json(id: @@data.add(collection, data))
|
60
110
|
end
|
61
111
|
|
112
|
+
#
|
113
|
+
# No PUT, POST.
|
114
|
+
# Add data with the id to the collection.
|
115
|
+
# endpoint:: collection name
|
116
|
+
# id:: unique identifier for the data
|
117
|
+
# Adds a collection if doesn't exist.
|
118
|
+
# Adds id and data at it if id doesn't exist.
|
119
|
+
# Otherwise, replaces data. Unless no data, then 403.
|
120
|
+
#
|
62
121
|
post '/:endpoint/:id' do
|
63
122
|
request.body.rewind
|
64
123
|
collection, id = params['endpoint'], params['id']
|
@@ -74,6 +133,12 @@ module Doppelserver
|
|
74
133
|
halt 403 unless @@data.update?(collection, id, data)
|
75
134
|
end
|
76
135
|
|
136
|
+
#
|
137
|
+
# Delete the data from
|
138
|
+
# endpoint:: collection name
|
139
|
+
# id:: with unique identifier
|
140
|
+
# Or 404 if one of those isn't found.
|
141
|
+
#
|
77
142
|
delete '/:endpoint/:id' do
|
78
143
|
request.body.rewind
|
79
144
|
collection, id = params['endpoint'], params['id']
|
data/lib/doppelserver/data.rb
CHANGED
@@ -1,31 +1,58 @@
|
|
1
1
|
module Doppelserver
|
2
|
+
#
|
3
|
+
# A glorified hash.
|
4
|
+
#
|
2
5
|
class Data
|
6
|
+
#
|
7
|
+
# Initiallizes (cleared) all internal data.
|
8
|
+
#
|
3
9
|
def initialize
|
4
10
|
@data = {}
|
5
11
|
@next_keys = {}
|
6
12
|
end
|
7
13
|
|
14
|
+
#
|
15
|
+
# Clears all internal data.
|
16
|
+
#
|
8
17
|
def clear
|
9
18
|
@data = {}
|
10
19
|
@next_keys = {}
|
11
20
|
end
|
12
21
|
|
22
|
+
#
|
23
|
+
# Returns the collection called parameter name.
|
24
|
+
#
|
13
25
|
def collection?(name)
|
14
26
|
@data.key?(name)
|
15
27
|
end
|
16
28
|
|
29
|
+
#
|
30
|
+
# Returns boolean, true if collection 1st param) exists
|
31
|
+
# and has key (2nd param).
|
32
|
+
#
|
17
33
|
def collection_key?(collection, key)
|
18
34
|
collection?(collection) && @data[collection].key?(key)
|
19
35
|
end
|
20
36
|
|
37
|
+
#
|
38
|
+
# Returns collection named parameter name.
|
39
|
+
#
|
21
40
|
def get_collection(name)
|
22
41
|
@data[name]
|
23
42
|
end
|
24
43
|
|
44
|
+
#
|
45
|
+
# Returns the value from the collection at first parameter
|
46
|
+
# at key of the second parameter.
|
47
|
+
#
|
25
48
|
def get_value(collection, key)
|
26
49
|
@data[collection][key]
|
27
50
|
end
|
28
51
|
|
52
|
+
#
|
53
|
+
# Adds the collection if that name (1st param) doesn't exist.
|
54
|
+
# Adds data (2nd param) to the collection regardless.
|
55
|
+
#
|
29
56
|
def add(collection, data)
|
30
57
|
unless collection?(collection)
|
31
58
|
@data[collection] = {}
|
@@ -37,6 +64,9 @@ module Doppelserver
|
|
37
64
|
next_key.to_s
|
38
65
|
end
|
39
66
|
|
67
|
+
#
|
68
|
+
# Updates collection[id] to new data.
|
69
|
+
#
|
40
70
|
def update?(collection, id, data)
|
41
71
|
data.each_key do |key|
|
42
72
|
return false unless @data[collection][id].key?(key)
|
@@ -47,6 +77,9 @@ module Doppelserver
|
|
47
77
|
true
|
48
78
|
end
|
49
79
|
|
80
|
+
#
|
81
|
+
# Deletes the data at key (2nd param) from collection (1st param).
|
82
|
+
#
|
50
83
|
def delete(collection, key)
|
51
84
|
@data[collection].delete(key)
|
52
85
|
end
|
data/lib/doppelserver/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doppelserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Cooper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|