whales_actions 0.1.1 → 0.1.2
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 +0 -3
- data/Gemfile.lock +5 -4
- data/Rakefile +1 -1
- data/lib/whales_actions/version.rb +1 -1
- data/lib/whales_controller/base.rb +6 -6
- data/lib/whales_dispatch/default_actions.rb +59 -59
- data/lib/whales_dispatch/flash.rb +2 -2
- data/lib/whales_dispatch/resource.rb +25 -25
- data/lib/whales_dispatch/router.rb +26 -25
- data/lib/whales_dispatch/session.rb +5 -3
- data/whales_actions.gemspec +3 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4f1a9a93db81f15a84a14a25821077d696a96b5
|
4
|
+
data.tar.gz: 8df87e596aed8593a70f9d25a16d80e539b9f93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8b2d94420fb72107228c08a0c89a4c62aa6beb5cc8f7f158798712b331a460da0a73a24f2016978f900cd169a1416265a75e8707f5b368008356c8b69c68d66
|
7
|
+
data.tar.gz: f97af9c79477326a1891188d3df84c848877a10d164c11d6dca84e7380c170551aa3d843a0bc88bda996a0095f03799f747803883247d2b0ccfc887637a7fd01
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
whales_actions (0.1.
|
4
|
+
whales_actions (0.1.1)
|
5
|
+
activesupport
|
6
|
+
json (= 1.8.3)
|
7
|
+
webrick
|
5
8
|
|
6
9
|
GEM
|
7
10
|
remote: https://rubygems.org/
|
8
11
|
specs:
|
9
|
-
activesupport (4.2.
|
12
|
+
activesupport (4.2.5)
|
10
13
|
i18n (~> 0.7)
|
11
14
|
json (~> 1.7, >= 1.7.7)
|
12
15
|
minitest (~> 5.1)
|
@@ -75,14 +78,12 @@ PLATFORMS
|
|
75
78
|
ruby
|
76
79
|
|
77
80
|
DEPENDENCIES
|
78
|
-
activesupport
|
79
81
|
bundler (~> 1.10)
|
80
82
|
guard
|
81
83
|
guard-rspec
|
82
84
|
pry
|
83
85
|
rake (~> 10.0)
|
84
86
|
rspec
|
85
|
-
webrick
|
86
87
|
whales_actions!
|
87
88
|
|
88
89
|
BUNDLED WITH
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ require_relative '../whales_dispatch/session'
|
|
10
10
|
|
11
11
|
module WhalesController
|
12
12
|
class Base
|
13
|
-
|
13
|
+
attr_reader :params
|
14
14
|
attr_accessor :res, :req
|
15
15
|
|
16
16
|
def initialize(request, response, route_params = {})
|
@@ -46,7 +46,7 @@ module WhalesController
|
|
46
46
|
self.res.body = content
|
47
47
|
@already_built_response = true
|
48
48
|
session.store_session(res)
|
49
|
-
flash.store_flash(res)
|
49
|
+
# flash.store_flash(res)
|
50
50
|
end
|
51
51
|
|
52
52
|
def redirect_to(url)
|
@@ -55,7 +55,7 @@ module WhalesController
|
|
55
55
|
self.res.status = 302
|
56
56
|
@already_built_response = true
|
57
57
|
session.store_session(res)
|
58
|
-
flash.store_flash(res)
|
58
|
+
# flash.store_flash(res)
|
59
59
|
end
|
60
60
|
|
61
61
|
def render(template_name, file_location = nil)
|
@@ -72,9 +72,9 @@ module WhalesController
|
|
72
72
|
private
|
73
73
|
|
74
74
|
def verify_authenticity_token
|
75
|
-
unless params[:authenticity_token] == session["authenticity_token"]
|
76
|
-
|
77
|
-
end
|
75
|
+
# unless params[:authenticity_token] == session["authenticity_token"]
|
76
|
+
# raise "Missing authenticity token"
|
77
|
+
# end
|
78
78
|
end
|
79
79
|
|
80
80
|
end
|
@@ -1,59 +1,59 @@
|
|
1
|
-
class DefaultActions
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
1
|
+
# class DefaultActions
|
2
|
+
# attr_reader :actions
|
3
|
+
# def initialize(resource)
|
4
|
+
# @resource = resource.to_s
|
5
|
+
# @resource_id = @resource.singularize + "_id"
|
6
|
+
# @actions = all
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# def parse_action_restrictions(restrictions_hash)
|
10
|
+
# raise(ArgumentError) if restrictions_hash.size > 1
|
11
|
+
# send(:only, restrictions_hash[:only]) if restrictions_hash[:only]
|
12
|
+
# send(:except, restrictions_hash[:except]) if restrictions_hash[:except]
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# def index
|
16
|
+
# { index: { suffix: "$", method: :get } }
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def show
|
20
|
+
# { show: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :post } }
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def new
|
24
|
+
# { new: { suffix: "/new$", method: :get } }
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# def create
|
28
|
+
# { create: { suffix: "$", method: :post } }
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# def edit
|
32
|
+
# { edit: { suffix: "/(?<#{@resource_id}>\\d+)/edit$", method: :get } }
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# def update
|
36
|
+
# { update: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :put } }
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# def destroy
|
40
|
+
# { destroy: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :delete } }
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# private
|
44
|
+
#
|
45
|
+
# def all
|
46
|
+
# DefaultActions.instance_methods(false).drop(2).reduce({}) do |accum, method|
|
47
|
+
# accum.merge(send(method))
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# def only(action_names)
|
52
|
+
# @actions.keep_if { |key, _| action_names.include?(key) }
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# def except(action_names)
|
56
|
+
# @actions.keep_if { |key, _| !action_names.include?(key) }
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# end
|
@@ -6,7 +6,7 @@ module WhalesDispatch
|
|
6
6
|
|
7
7
|
def initialize(request)
|
8
8
|
request.cookies.each do |cookie|
|
9
|
-
@value_for_now = JSON.parse(cookie.value) if cookie.name == '
|
9
|
+
@value_for_now = JSON.parse(cookie.value) if cookie.name == '_whales_flash'
|
10
10
|
end
|
11
11
|
@value_for_now ||= {}
|
12
12
|
@value_for_next = {}
|
@@ -26,7 +26,7 @@ module WhalesDispatch
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def store_flash(response)
|
29
|
-
cookie = WEBrick::Cookie.new('
|
29
|
+
cookie = WEBrick::Cookie.new('_whales_flash', @value_for_next.to_json)
|
30
30
|
cookie.path = '/'
|
31
31
|
response.cookies << cookie
|
32
32
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
class Resource
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
1
|
+
# class Resource
|
2
|
+
# attr_reader :pattern
|
3
|
+
#
|
4
|
+
# def initialize(noun, suffix, parent)
|
5
|
+
# @noun = noun.to_s
|
6
|
+
# @pattern = build_route_pattern(suffix, parent)
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# def build_route_pattern(suffix, parent)
|
10
|
+
# base = build_base(parent)
|
11
|
+
# Regexp.new(base + @noun + suffix)
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# def build_base(parent)
|
15
|
+
# if parent.empty?
|
16
|
+
# "^/"
|
17
|
+
# else
|
18
|
+
# "^/#{parent}/(?<#{parent.singularize}_id>\\d+)/"
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def classify
|
23
|
+
# klass = Object.const_get(@noun.capitalize + "Controller")
|
24
|
+
# end
|
25
|
+
# end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module WhalesDispatch
|
2
2
|
class Router
|
3
3
|
|
4
|
+
HTML_METHODS = [:get, :post, :patch, :put, :delete]
|
4
5
|
attr_reader :routes
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
@routes = []
|
8
|
-
@last_parent_route = ""
|
9
|
+
# @last_parent_route = ""
|
9
10
|
end
|
10
11
|
|
11
12
|
def add_route(pattern, method, controller_class, action_name)
|
@@ -16,30 +17,30 @@ module WhalesDispatch
|
|
16
17
|
instance_eval(&proc)
|
17
18
|
end
|
18
19
|
|
19
|
-
def resources(controller_noun, scope, **action_restrictions)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
# def resources(controller_noun, scope, **action_restrictions)
|
21
|
+
# @last_parent_route = "" if scope == :parent
|
22
|
+
# controller_actions = DefaultActions.new(controller_noun)
|
23
|
+
# controller_actions.parse_action_restrictions(action_restrictions)
|
24
|
+
# build_resources(controller_noun, controller_actions)
|
25
|
+
#
|
26
|
+
# if block_given?
|
27
|
+
# @last_parent_route = controller_noun.to_s
|
28
|
+
# yield
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# def build_resources(controller_noun, controller_actions)
|
33
|
+
# controller_actions.actions.each do |action_name, action_hash|
|
34
|
+
#
|
35
|
+
# resource = Resource.new(
|
36
|
+
# controller_noun, action_hash[:suffix], @last_parent_route
|
37
|
+
# )
|
38
|
+
#
|
39
|
+
# send action_hash[:method], resource.pattern, resource.classify, action_name
|
40
|
+
# end
|
41
|
+
# end
|
24
42
|
|
25
|
-
|
26
|
-
@last_parent_route = controller_noun.to_s
|
27
|
-
yield
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def build_resources(controller_noun, controller_actions)
|
32
|
-
controller_actions.actions.each do |action_name, action_hash|
|
33
|
-
|
34
|
-
resource = Resource.new(
|
35
|
-
controller_noun, action_hash[:suffix], @last_parent_route
|
36
|
-
)
|
37
|
-
|
38
|
-
send action_hash[:method], resource.pattern, resource.classify, action_name
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
[:get, :post, :put, :delete].each do |http_method|
|
43
|
+
HTML_METHODS.each do |http_method|
|
43
44
|
define_method(http_method) do |pattern, controller_class, action_name|
|
44
45
|
add_route(pattern, http_method, controller_class, action_name)
|
45
46
|
end
|
@@ -58,6 +59,6 @@ module WhalesDispatch
|
|
58
59
|
res.body = "Could not find matching route."
|
59
60
|
end
|
60
61
|
end
|
61
|
-
|
62
|
+
|
62
63
|
end
|
63
64
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'yaml'
|
2
2
|
require 'webrick'
|
3
3
|
|
4
4
|
module WhalesDispatch
|
@@ -6,7 +6,7 @@ module WhalesDispatch
|
|
6
6
|
|
7
7
|
def initialize(request)
|
8
8
|
request.cookies.each do |cookie|
|
9
|
-
@value =
|
9
|
+
@value = YAML.load(cookie.value) if cookie.name == '_whales_app'
|
10
10
|
end
|
11
11
|
@value ||= {}
|
12
12
|
end
|
@@ -20,9 +20,11 @@ module WhalesDispatch
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def store_session(response)
|
23
|
-
cookie = WEBrick::Cookie.new('
|
23
|
+
cookie = WEBrick::Cookie.new('_whales_app', @value.to_yaml)
|
24
|
+
puts "got past cookie"
|
24
25
|
cookie.path = '/'
|
25
26
|
response.cookies << cookie
|
27
|
+
puts "added cookie to response"
|
26
28
|
end
|
27
29
|
|
28
30
|
end
|
data/whales_actions.gemspec
CHANGED
@@ -15,6 +15,9 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
16
|
spec.require_paths = ["lib"]
|
17
17
|
|
18
|
+
spec.add_dependency "activesupport"
|
19
|
+
spec.add_dependency "webrick"
|
20
|
+
|
18
21
|
spec.add_development_dependency "bundler", "~> 1.10"
|
19
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
20
23
|
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whales_actions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Horton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webrick
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|