are_you_sure 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: bcd7edc4ed641ec451b630969d5cb73827391288
4
- data.tar.gz: 04b79123503d1fbb8ef06427a5f228e653fafec3
3
+ metadata.gz: 4690d42c5e420098af7909cc52201c9ce32cabe4
4
+ data.tar.gz: 5de10e9fe31de9a96f450347786f92b93d031797
5
5
  SHA512:
6
- metadata.gz: 582f128024ae6f6ca1d4839103697d0a5b52aa1d19eb582e63cfe2afae2a4ddb1973e5fb00a7542639fd77209940a53941bc448aab8d0bfa5aaadc077b5f5ed6
7
- data.tar.gz: 1a5b9d3292a4e1680efe13c642136fdbbf584e8656ef40795baf4cebbde74e018e4ef1daba3b851fc09652a3f8ef06d564f8f32ec0018f9f532709130f552d9c
6
+ metadata.gz: 3797c6097ab201109c556bcfe2d69c0bace347d5b31f29e29e1d3ef26e282e2bc7a1c57615db7a771b02efbb1efa3eca32dcfb937e838a6f5d9fe1c6a17eceb1
7
+ data.tar.gz: 4d70e98d946e32b3bee83a83c23d4c3162702b069e197a7727cbe77a82befffb99068a4c568d844293239799fe4c68248de2cb2ca97eef637d6fcecd3add6e1b
@@ -4,10 +4,18 @@ module AreYouSure
4
4
 
5
5
  def confirm_for(model)
6
6
  model.extend(Confirmable).tap do |model|
7
- model.confirmed = param_confirmed
7
+ model.prepare_confirmation(param_confirmed, session)
8
8
  end
9
9
  end
10
10
 
11
+ def fill_confirmed(model)
12
+ confirm_for(model).tap do |model|
13
+ model.fill_confirmed_attributes
14
+ end
15
+ end
16
+
17
+ private
18
+
11
19
  def param_confirmed
12
20
  params[:confirmed]
13
21
  end
@@ -1,28 +1,28 @@
1
1
  module AreYouSure
2
2
  module Confirmable
3
3
 
4
- def confirmed=(confirmed)
4
+ def prepare_confirmation(confirmed, session)
5
5
  @are_you_sure_confirmed = confirmed
6
+ @are_you_sure_session = session
7
+ end
8
+
9
+ def fill_confirmed_attributes
10
+ self.attributes = @are_you_sure_session[:model_attributes]
11
+ clear_attributes_cache
6
12
  end
7
13
 
8
14
  def save_if_confirmed
9
- do_if_valid_and_confirmed do
10
- self.save
11
- end
15
+ confirm_with_persist { self.save }
12
16
  end
13
17
 
14
18
  def update_if_confirmed(attributes)
15
19
  self.attributes = attributes
16
- do_if_valid_and_confirmed do
17
- self.update(attributes)
18
- end
20
+ confirm_with_persist { self.update(attributes) }
19
21
  end
20
22
 
21
23
  def update_attributes_if_confirmed(attributes)
22
24
  self.attributes = attributes
23
- do_if_valid_and_confirmed do
24
- self.update_attributes(attributes)
25
- end
25
+ confirm_with_persist { self.update_attributes(attributes) }
26
26
  end
27
27
 
28
28
  def update_attribute_if_confirmed(name, value)
@@ -39,10 +39,19 @@ module AreYouSure
39
39
 
40
40
  private
41
41
 
42
- def do_if_valid_and_confirmed
42
+ def confirm_with_persist
43
43
  return false unless self.valid?
44
- return false unless confirmed?
45
- yield
44
+ if confirmed?
45
+ clear_attributes_cache
46
+ yield
47
+ else
48
+ @are_you_sure_session[:model_attributes] = self.attributes
49
+ false
50
+ end
51
+ end
52
+
53
+ def clear_attributes_cache
54
+ @are_you_sure_session[:model_attributes] = nil
46
55
  end
47
56
  end
48
57
  end
@@ -18,7 +18,10 @@ module AreYouSure
18
18
  end
19
19
 
20
20
  def cancel(value=nil, options={})
21
- @template.link_to(value || I18n.t('are_you_sure.helpers.cancel', default: 'Cancel'), :back)
21
+ @template.link_to(
22
+ value || I18n.t('are_you_sure.helpers.cancel', default: 'Cancel'),
23
+ @template.polymorphic_path(@object, action: @object.persisted? ? :edit : :new)
24
+ )
22
25
  end
23
26
 
24
27
  def method_missing(method, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module AreYouSure
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: are_you_sure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - haazime
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails