whales_actions 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/whales_actions/version.rb +1 -1
- data/lib/whales_controller/base.rb +5 -5
- data/lib/whales_dispatch/default_actions.rb +59 -59
- data/lib/whales_dispatch/resource.rb +25 -25
- data/lib/whales_dispatch/router.rb +22 -22
- data/lib/whales_dispatch/session.rb +3 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ecae3119c2ffc12414e91eaf3fac2e0b1f4176
|
4
|
+
data.tar.gz: dab55c6a86c22990c2b8752ae7fe56afded4fd9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 633406531f3e53344e7c6c1ae4ab32955dc6c184049919160b0a4e73e0e59f129f60547aea9e7ad485bb94c23bb7ee7c0f8f87e3bbbb94ffabae3d411e96c04f
|
7
|
+
data.tar.gz: b1ebd2525e958ebdaae24fd364768e7251de7b8fee23dd822debc81b1cc3df1262c2d5a860f828eb29770f6df28bcfc8704b50b1c6ad07f012c31a3d0d44c7d2
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -1,25 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
@@ -17,28 +17,28 @@ module WhalesDispatch
|
|
17
17
|
instance_eval(&proc)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
42
42
|
|
43
43
|
HTML_METHODS.each do |http_method|
|
44
44
|
define_method(http_method) do |pattern, controller_class, action_name|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'yaml'
|
2
1
|
require 'webrick'
|
2
|
+
require 'json'
|
3
3
|
|
4
4
|
module WhalesDispatch
|
5
5
|
class Session
|
6
6
|
|
7
7
|
def initialize(request)
|
8
8
|
request.cookies.each do |cookie|
|
9
|
-
@value =
|
9
|
+
@value = JSON.parse(cookie.value) if cookie.name == '_whales_app'
|
10
10
|
end
|
11
11
|
@value ||= {}
|
12
12
|
end
|
@@ -20,11 +20,9 @@ module WhalesDispatch
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def store_session(response)
|
23
|
-
cookie = WEBrick::Cookie.new('_whales_app', @value.
|
24
|
-
puts "got past cookie"
|
23
|
+
cookie = WEBrick::Cookie.new('_whales_app', @value.to_json)
|
25
24
|
cookie.path = '/'
|
26
25
|
response.cookies << cookie
|
27
|
-
puts "added cookie to response"
|
28
26
|
end
|
29
27
|
|
30
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.5.
|
176
|
+
rubygems_version: 2.5.1
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: The VC in the Whales MVC framework
|