rails5_xhr_update 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/lib/rails5_xhr_update/cli.rb +1 -0
- data/lib/rails5_xhr_update/version.rb +1 -1
- data/lib/rails5_xhr_update/xhr_to_rails5.rb +20 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 617d1833f375a4e5cff4712f90a98a1618754a14
|
4
|
+
data.tar.gz: 1652b16844179fa4fe0558821bfcc387b3ad9431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e4756ae63f858884c861bbe48d1818df9188d4d10e7bdb04bbcf9fa13c7a1b3bf9124ec8b89e8d382de5254c5ca77bd0b6231f51db756f409445eb58a064148
|
7
|
+
data.tar.gz: 7c80335e30b5d243bcb50946696235f5da47f3a60cbda98ab34ab2b88a923f28dd681d7ee6657482033b1cbe15e7aa6f61cc833771f9e4440baf251ff494ee51
|
data/CHANGES.md
CHANGED
@@ -20,7 +20,7 @@ module Rails5XHRUpdate
|
|
20
20
|
def on_send(node)
|
21
21
|
return if node.children[1] != :xhr
|
22
22
|
arguments = extract_and_validate_arguments(node)
|
23
|
-
children = initial_children(node) + add_xhr_node(
|
23
|
+
children = initial_children(node) + add_xhr_node(arguments)
|
24
24
|
replace(node.loc.expression, Rails5XHRUpdate.ast_to_string(
|
25
25
|
node.updated(nil, children)
|
26
26
|
))
|
@@ -28,23 +28,24 @@ module Rails5XHRUpdate
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def add_xhr_node(
|
31
|
+
def add_xhr_node(arguments)
|
32
32
|
children = []
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
unless session.nil? || session.children.empty?
|
33
|
+
arguments.keys.sort.each do |argument|
|
34
|
+
value = arguments[argument]
|
35
|
+
children << Rails5XHRUpdate.ast_pair(argument, value) \
|
36
|
+
unless value.nil? || value.children.empty?
|
37
|
+
end
|
39
38
|
children << Rails5XHRUpdate.ast_pair(:xhr, AST_TRUE)
|
40
39
|
[Parser::AST::Node.new(:hash, children)]
|
41
40
|
end
|
42
41
|
|
43
42
|
def extract_and_validate_arguments(node)
|
44
43
|
arguments = node.children[4..-1]
|
45
|
-
|
44
|
+
if (keyword_arguments = handle_keyword_args(arguments))
|
45
|
+
return keyword_arguments
|
46
|
+
end
|
46
47
|
raise Exception, "Unhandled:\n\n #{arguments}" if arguments.size > 3
|
47
|
-
arguments
|
48
|
+
{ params: arguments[0], session: arguments[1], flash: arguments[2] }
|
48
49
|
end
|
49
50
|
|
50
51
|
def initial_children(node)
|
@@ -53,11 +54,18 @@ module Rails5XHRUpdate
|
|
53
54
|
[nil, http_method, http_path]
|
54
55
|
end
|
55
56
|
|
56
|
-
def
|
57
|
+
def handle_keyword_args(arguments)
|
57
58
|
return false if arguments.size != 1
|
58
59
|
return false if arguments[0].children.empty?
|
59
60
|
first_key = arguments[0].children[0].children[0].children[0]
|
60
|
-
%i[params session flash].include?(first_key)
|
61
|
+
return false unless %i[params session flash format].include?(first_key)
|
62
|
+
|
63
|
+
result = {}
|
64
|
+
arguments[0].children.each do |node|
|
65
|
+
raise Exception, "unexpected #{node}" if node.children.size != 2
|
66
|
+
result[node.children[0].children[0]] = node.children[1]
|
67
|
+
end
|
68
|
+
result
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails5_xhr_update
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Boe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|