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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bebf3fb70c994c0ecbba11d24a15bc3a7397d771df23f59822b977bb5314a790
4
- data.tar.gz: 3f262e434afc3b66bcf9a88e293eeb2fa5dae4324190f7274dc2b2ff0bef9542
3
+ metadata.gz: c8ecd7f77f59921d42f9f6b3dc9a49f6209c4f315aa0325c8e6b266e58fa6f26
4
+ data.tar.gz: fe58b716b71ab2e73ae34441f020e850090f174952995daa6204f6e24801ea2e
5
5
  SHA512:
6
- metadata.gz: e2e80557e1888337bad21d75fad14bbf50347878f5cfa23fd63d0d281f67525ff3b347cd2cf2b5411758ec47a42b9438396e0e9ca5fc9f931535f49a4b014332
7
- data.tar.gz: 86ad1724ca9c4f4d4e3a2118350ec50fc4eca12655bf304e58523dfe0505a2c9a6de6d4bb7545cf41ff158df9083d38758a1b3fb9433244c370a9c36353f1a6c
6
+ metadata.gz: e74ec8e4724ad41eae0b1eef6f95abcfd500efd2656c72a92c64f11ec2ceb824e2112860d6e4ab8b8f1cde9e9105ec920546fbd4f08b6554101c2adec2e2f2f8
7
+ data.tar.gz: e4cf2ac4da81bd7af95cba53de81a1bfa6e2bc92f184ae5e75b65748a7ad13e93d004adf7f9ca986e2c369206f4e32ee729f775044a2a0850cbfd832d4d41a64
data/.gitignore CHANGED
@@ -1,9 +1,10 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
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
  [![CircleCI](https://circleci.com/gh/drewcoo/doppelserver.svg?style=shield)](https://circleci.com/gh/drewcoo/doppelserver)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/drewcoo/doppelserver/badge.svg?branch=master)](https://coveralls.io/github/drewcoo/doppelserver?branch=master)
6
6
  [![Gem Version](https://badge.fury.io/rb/doppelserver.svg)](https://badge.fury.io/rb/doppelserver)
7
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/dd50d7ee18ae46c38ad053cf3dc59794)](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
- TODO: Write usage instructions here
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
@@ -1,6 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
7
+ RuboCop::RakeTask.new
8
+
6
9
  task default: :spec
@@ -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']
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Doppelserver
2
- VERSION = '0.2.6'.freeze
2
+ VERSION = '0.2.7'.freeze
3
3
  end
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.6
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-05-27 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport