parakeet 0.1.0 → 0.1.1
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/Gemfile.lock +1 -1
- data/design_document.txt +37 -0
- data/lib/parakeet/action.rb +0 -0
- data/lib/parakeet/controller_addons.rb +27 -0
- data/lib/parakeet/guideline.rb +29 -0
- data/lib/parakeet/parameter.rb +10 -0
- data/lib/parakeet/version.rb +1 -1
- data/lib/parakeet.rb +3 -18
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec7882c8e0e5b061e780ddfd41b8e0f1f864ddb9
|
4
|
+
data.tar.gz: 707d3e319cc66a346e34e6e33c2f856055f41969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20b61447864c99b376b561ce0bc59ffe57c09d22b37002bf696ebbec42a876a5bd75f9cf6272112e9b8a29aac15683393ee167b579af5446726626cc50f0c5c1
|
7
|
+
data.tar.gz: 99f8a299d03ca6fcf787055888d18e5d2dbabf6cc8e7e5bd873750693d8bc1962d2ac0fafa4c1432f9d7f23e0218bc08e2a12ed995dfb980b9cd4f3922603b33
|
data/Gemfile.lock
CHANGED
data/design_document.txt
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Summary:
|
2
|
+
1) before_action is going to run before each of the actions in the controller
|
3
|
+
2) Enable ability to select individual actions or all, this may just be covered
|
4
|
+
if the before_action has an entry in the hash for that action or not.
|
5
|
+
3) An initializer/configuration file will be used to set the configuration of Parakeet and to pass in
|
6
|
+
the hash that will contain the controller, action, parameter name, and parameter type.
|
7
|
+
4) The before_action will iterate over the expected params for this action, check
|
8
|
+
if they are in the params hash, and if they are, check if they are in the correct format.
|
9
|
+
5) Return an object with errors. Probably similar to the error already returned by rails.
|
10
|
+
Maybe actively try to mimic the format. Give list of parameters that are
|
11
|
+
missing/invalid and return to the user as an instance variable.
|
12
|
+
|
13
|
+
Features:
|
14
|
+
1) Mandatory/Optional parameter checking in the param hash for both existence,
|
15
|
+
and format/value.
|
16
|
+
2) Potentially try and turn parameters into the expect form. Turn a string into
|
17
|
+
an int if that is desired.
|
18
|
+
3) CLI to create the configuration file.
|
19
|
+
4) Maybe create a way for the API to automatically return an error with the error object.
|
20
|
+
5) Perhaps enable customization of the error message/error response.
|
21
|
+
|
22
|
+
Classes/Modules:
|
23
|
+
1) Error
|
24
|
+
2) Expected parameter (perhaps created on initialization with the configuration info, probably no reason for this anyways.)
|
25
|
+
3) Configuration?
|
26
|
+
4) ControllerAdditions (To handle the items mixed in to the base Controller)
|
27
|
+
|
28
|
+
ToDo:
|
29
|
+
1) Review other gems to see class/module set up.
|
30
|
+
1b) Flesh out a bit more sophisticated class layout then this document presents to make it
|
31
|
+
easier to move forward.
|
32
|
+
1c) A clearer vision will also enable me to do a bit more targeted TDD as opposed to just
|
33
|
+
winging it
|
34
|
+
|
35
|
+
In Progress Design Doc
|
36
|
+
https://docs.google.com/document/d/1WQjCEmi5zS6S2IsDhvgS57BlsKrz9Erc3782GcBuG9s/edit
|
37
|
+
Last Updated: January 31st
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Parakeet
|
2
|
+
# TODO: Update to 2017 using ActiveSupport::Concern
|
3
|
+
module ControllerAddons
|
4
|
+
module ClassMethods
|
5
|
+
def verify_parameters
|
6
|
+
self.send(:before_action, :verify_parameters)
|
7
|
+
end
|
8
|
+
|
9
|
+
def guideline
|
10
|
+
@guideline ||= ::Guideline.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
module InstanceMethods
|
14
|
+
def check_mixin
|
15
|
+
puts "ClassMethod successfully mixed in 12"
|
16
|
+
end
|
17
|
+
def verify_parameters
|
18
|
+
logger.info ActionController::Base.guideline.controller_actions
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined? ActionController::Base
|
24
|
+
ActionController::Base.extend ControllerAddons::ClassMethods
|
25
|
+
ActionController::Base.include ControllerAddons::InstanceMethods
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Parakeet
|
2
|
+
module Guideline
|
3
|
+
|
4
|
+
# This will be included in a Guideline class that the user will
|
5
|
+
# generate and define the parameters/vallidations.
|
6
|
+
# class Guideline
|
7
|
+
# include Parakeet::Guideline
|
8
|
+
# def initialize
|
9
|
+
# verify_params('user#create', 'first_name', :string, { exists: true, length: 'under 10' })
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
|
13
|
+
# This seems like a super duplicative way to do this.
|
14
|
+
# Can pass in object that contains controller/action and ActionController
|
15
|
+
# and all parameters/types/validations instead. Is that just as messy?
|
16
|
+
# TODO: Update with a DRYer solution considering multiple parameters for a
|
17
|
+
# controller action
|
18
|
+
def verify_params(controller_action, parameter, type, validations)
|
19
|
+
# TODO: I'm thinking that this should create an object that represents
|
20
|
+
# an action. Then into that object insert the individual parameter rules.
|
21
|
+
# controller_actions[controller_action] = [] if controller_actions[controller_action].nil?
|
22
|
+
controller_actions[controller_action] << Parameter.new(parameter, type, validations)
|
23
|
+
end
|
24
|
+
|
25
|
+
def controller_actions
|
26
|
+
@controller_actions ||= Hash.new{ |hash, key| hash[key] = [] }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/parakeet/version.rb
CHANGED
data/lib/parakeet.rb
CHANGED
@@ -1,19 +1,4 @@
|
|
1
1
|
require "parakeet/version"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
def check_mixin
|
6
|
-
puts "ClassMethod successfully mixed in"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.included(base)
|
11
|
-
base.extend ClassMethods
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
if defined? ActionController::Base
|
16
|
-
ActionController::Base.class_eval do
|
17
|
-
include Parakeet
|
18
|
-
end
|
19
|
-
end
|
2
|
+
require "parakeet/controller_addons"
|
3
|
+
require "parakeet/parameter"
|
4
|
+
require "parakeet/guideline"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parakeet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Fike
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,7 +70,12 @@ files:
|
|
70
70
|
- Rakefile
|
71
71
|
- bin/console
|
72
72
|
- bin/setup
|
73
|
+
- design_document.txt
|
73
74
|
- lib/parakeet.rb
|
75
|
+
- lib/parakeet/action.rb
|
76
|
+
- lib/parakeet/controller_addons.rb
|
77
|
+
- lib/parakeet/guideline.rb
|
78
|
+
- lib/parakeet/parameter.rb
|
74
79
|
- lib/parakeet/version.rb
|
75
80
|
- parakeet.gemspec
|
76
81
|
homepage: https://github.com/colinfike/parakeet
|