rails-sweetalert2-confirm 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eeb4081353a69ee10a183653fd4e7075f89fd20023fe27f3efe174468035736
4
- data.tar.gz: 67a6c67e158a6bd5f5f5960d3ea6bfa83d6a91edd36f74af054e336a2b57cba8
3
+ metadata.gz: d5bf640acac05705af83e22b000f8c7089122fed38c1826463ddf770c18c3ee1
4
+ data.tar.gz: 614e66aa79624a8f744d1f843437270c7abdc1a28d60f564bddb5792c95924f8
5
5
  SHA512:
6
- metadata.gz: 85e0cf7c29017a3b5622080d49977a2f3bac352e85ea8fe6b5d5333a4650e52d58352d89a685d8db09f1c55de72a5157537f705c430f23c0d0abb787fdd33852
7
- data.tar.gz: 4936068d2d56909404cad014ed46c9df661069961f562a3bf197d01d47b1ecbaec67aeb83c89d4fabd2e1ef2ccd6ec8a2ecced86b601b32f83f43a5fdda90cad
6
+ metadata.gz: 2cb5b3cd4c5a65e8c3b55b8500d7bce4a913d341469f5fc6d03a2ff601fd9d089621508cffc6d9cc655dab8cc44b38201db9df6aafaf78d74a93abbc89b46461
7
+ data.tar.gz: c8fbf9c8220b1e9175be9766874445f380e185102215b29a66c4797d5842f9efb6dba2e329239b8cc5005aadd792ba7642c53d9351d2a5101ce1f176b15b4f94
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_sweetalert2_confirm/version'
2
4
  require 'rails_sweetalert2_confirm/railtie'
3
5
  require 'rails_sweetalert2_confirm/rails/engine'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsSweetAlert2Confirm
2
4
  module Rails
3
5
  class Engine < ::Rails::Engine
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_sweetalert2_confirm/view_helpers'
4
+
2
5
  module RailsSweetAlert2Confirm
3
6
  class Railtie < Rails::Railtie
4
7
  initializer 'rails_sweetalert2_confirm.view_helpers' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsSweetAlert2Confirm
2
- VERSION = "0.9.9"
4
+ VERSION = "0.9.10"
3
5
  end
@@ -1,10 +1,6 @@
1
- module RailsSweetAlert2Confirm
2
- SWAL_OPTIONS_MAPPINGS = {
3
- confirm: :title,
4
- remote: :remote,
5
- method: :method
6
- }
1
+ # frozen_string_literal: true
7
2
 
3
+ module RailsSweetAlert2Confirm
8
4
  module ViewHelpers
9
5
  def link_to(*args, &block)
10
6
  options = args[block_given? ? 1 : 2] || {}
@@ -23,37 +19,38 @@ module RailsSweetAlert2Confirm
23
19
  super(*args, &block)
24
20
  end
25
21
 
26
- protected
27
-
28
- def merge_options_into_swal(options)
29
- options = merge_confirm_into_swal(options)
30
- options = merge_remote_into_swal(options)
31
- merge_method_into_swal(options)
32
- end
33
-
34
- %w(remote method confirm).each do |option|
35
- define_method("merge_#{option}_into_swal") do |options|
36
- return if %w(remote method).include?(option) && !options_has_confirm?
37
- if send("options_has_#{option}?", options)
38
- options[:data] ||= {}
39
- options[:data][:swal] ||= {}
40
- option = option.to_sym
41
- options[:data][:swal][SWAL_OPTIONS_MAPPINGS[option]] =
42
- if option == :method
43
- options[option] ||
44
- options[:data][option]
45
- else
46
- options.delete(option) ||
47
- options[:data].delete(option)
48
- end
49
- end
50
- options
51
- end
52
-
53
- define_method("options_has_#{option}?") do |options|
54
- option = option.to_sym
55
- (options[option] || options[:data].try(:[], option)).present?
56
- end
22
+ private def merge_options_into_swal(options)
23
+ return options unless options_have_confirm?(options)
24
+ options = configure_swal_options(options)
25
+ options = merge_swal_remote_options(options)
26
+ options = merge_swal_confirm_options(options)
27
+ end
28
+
29
+ private def configure_swal_options(options)
30
+ options[:data] ||= {}
31
+ options[:data][:swal] ||= {}
32
+ end
33
+
34
+ private def merge_swal_remote_options(options)
35
+ return options unless options_have_remote?(options)
36
+ options[:data][:swal][:remote] = fetch_option(:remote, options)
37
+ end
38
+
39
+ private def merge_swal_confirm_options(options)
40
+ return options unless options_have_confirm?(options)
41
+ options[:data][:swal][:title] = fetch_option(:confirm, options)
42
+ end
43
+
44
+ private def fetch_option(option, options)
45
+ options.delete(option) || options[:data].delete(option)
46
+ end
47
+
48
+ private def options_have_confirm?(options)
49
+ (options[:confirm] || options.dig(:data, :confirm)).present?
50
+ end
51
+
52
+ private def options_have_remote?(options)
53
+ (options[:remote] || options.dig(:data, :remote)).present?
57
54
  end
58
55
  end
59
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-sweetalert2-confirm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Woodward
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-12 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails