are_you_sure 0.1.0 → 0.2.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:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4690d42c5e420098af7909cc52201c9ce32cabe4
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5de10e9fe31de9a96f450347786f92b93d031797
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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. 
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
       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 
     | 
    
         
            -
                   
     | 
| 
       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 
     | 
    
         
            -
                   
     | 
| 
       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  
     | 
| 
      
 42 
     | 
    
         
            +
                def confirm_with_persist
         
     | 
| 
       43 
43 
     | 
    
         
             
                  return false unless self.valid?
         
     | 
| 
       44 
     | 
    
         
            -
                   
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 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( 
     | 
| 
      
 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)
         
     | 
    
        data/lib/are_you_sure/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-01-04 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     |