rails5_xhr_update 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: fee933190f7c4836569a6925afd4281466e6150d
4
- data.tar.gz: 429a19dc4003f90b164972afd2ef3a6c89c9f33b
3
+ metadata.gz: 617d1833f375a4e5cff4712f90a98a1618754a14
4
+ data.tar.gz: 1652b16844179fa4fe0558821bfcc387b3ad9431
5
5
  SHA512:
6
- metadata.gz: '09777cb0429c67a9e58a4c7597fb3715428cfefdcca1503d266b7238de5d508f17a290d1883a31bba55802f5790e5cd43f3602479617352f7b6d9d9cc1b943e6'
7
- data.tar.gz: 0a16fb5c56d32435e5bcd710bdcbe41fe599ebcdc8353dd66de974fe609674961e06e9218ac4f3bf7515ff6eee31400328189ded031afd5df523c95fa33546b0
6
+ metadata.gz: 4e4756ae63f858884c861bbe48d1818df9188d4d10e7bdb04bbcf9fa13c7a1b3bf9124ec8b89e8d382de5254c5ca77bd0b6231f51db756f409445eb58a064148
7
+ data.tar.gz: 7c80335e30b5d243bcb50946696235f5da47f3a60cbda98ab34ab2b88a923f28dd681d7ee6657482033b1cbe15e7aa6f61cc833771f9e4440baf251ff494ee51
data/CHANGES.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.4.0 (2018/06/14)
4
+
5
+ __Added__
6
+
7
+ * Support keyword arguments to `xhr`.
8
+ * Support the `format` keyword argument to `xhr`.
9
+
3
10
  ## 0.3.0 (2018/05/26)
4
11
 
5
12
  __Added__
@@ -45,6 +45,7 @@ module Rails5XHRUpdate
45
45
  config.on('-w', '--write', 'Write changes back to files') do |write|
46
46
  @options[:write] = write
47
47
  end
48
+ config.version = Rails5XHRUpdate::VERSION
48
49
  end.parse!
49
50
  end
50
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rails5XHRUpdate
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -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(*arguments)
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(params = nil, session = nil, flash = nil)
31
+ def add_xhr_node(arguments)
32
32
  children = []
33
- children << Rails5XHRUpdate.ast_pair(:flash, flash) \
34
- unless flash.nil? || flash.children.empty?
35
- children << Rails5XHRUpdate.ast_pair(:params, params) \
36
- unless params.nil? || params.children.empty?
37
- children << Rails5XHRUpdate.ast_pair(:session, session) \
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
- raise Exception, 'should this happen?' if keyword_args?(arguments)
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 keyword_args?(arguments)
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.3.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-05-26 00:00:00.000000000 Z
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest