activerecord_cloneable 0.3.4 → 0.3.5
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 +4 -4
- data/activerecord_cloneable.gemspec +1 -1
- data/lib/active_record/cloneable.rb +8 -3
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 27cf2329d412714a2cb9cccba564b870e34af022
         | 
| 4 | 
            +
              data.tar.gz: 9a9009d8a1353ee9ae0a6ab2c0f344a9850dcd18
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e42c32c05ab3371c6ab06720187ea19113d4449395aa6a2ec8c385467859e1ebbf39c0130229ec5f8bef21977a0c74d76854ff93296316e0b31a202f79f91eeb
         | 
| 7 | 
            +
              data.tar.gz: c840068eb59f07d60cf6886060e8bcd61cadce72487d810db0e5ca389dc2315b4e5a56995d4e34fb93593917ff054b1abae16d146ccfcd5fe39073df6d0f83af
         | 
| @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            Gem::Specification.new do |s|
         | 
| 2 2 | 
             
              s.name = 'activerecord_cloneable'
         | 
| 3 | 
            -
              s.version = '0.3. | 
| 3 | 
            +
              s.version = '0.3.5'
         | 
| 4 4 | 
             
              s.summary = "A library to help clone active records - that is, generate active new record objects with the data copied from an existing record."
         | 
| 5 5 | 
             
              s.authors = ["Adam Palmblad"]
         | 
| 6 6 | 
             
              s.email = 'apalmblad@gmail.com'
         | 
| @@ -53,6 +53,7 @@ module ActiveRecord::Cloneable | |
| 53 53 | 
             
                      begin
         | 
| 54 54 | 
             
                        rec = obj.clone_record( skipped_children: args[:skipped_children] + [self],
         | 
| 55 55 | 
             
                            cloned_parents: args[:cloned_parents] + [self],
         | 
| 56 | 
            +
                            stack: args[:stack] + [ parent_relation.name ],
         | 
| 56 57 | 
             
                            skipped_child_relations: find_applicable_clone_args( parent_relation.name, args[:skipped_child_relations] ),
         | 
| 57 58 | 
             
                            skipped_parent_relations: find_applicable_clone_args( parent_relation.name, args[:skipped_parent_relations] ),
         | 
| 58 59 | 
             
                            shared_parent_relations: find_applicable_clone_args( parent_relation.name, args[:shared_parent_relations] )
         | 
| @@ -75,7 +76,7 @@ module ActiveRecord::Cloneable | |
| 75 76 | 
             
                      nil
         | 
| 76 77 | 
             
                    end
         | 
| 77 78 | 
             
                  end
         | 
| 78 | 
            -
                  r_val.flatten
         | 
| 79 | 
            +
                  r_val.flatten.compact
         | 
| 79 80 | 
             
                end
         | 
| 80 81 | 
             
                # ---------------------------------------------------- clone_child_relation?
         | 
| 81 82 | 
             
                def clone_child_relation?( relation_name, skipped_child_relations )
         | 
| @@ -94,6 +95,7 @@ module ActiveRecord::Cloneable | |
| 94 95 | 
             
                  args[:cloned_parents] ||= []
         | 
| 95 96 | 
             
                  args[:skipped_children] ||= []
         | 
| 96 97 | 
             
                  args[:attributes] ||={}
         | 
| 98 | 
            +
                  args[:stack] ||= []
         | 
| 97 99 | 
             
                  cloned_record = args[:object] || self.class.new
         | 
| 98 100 | 
             
                  data = {}
         | 
| 99 101 | 
             
                  self.class.reflections.each do |k,v|
         | 
| @@ -115,6 +117,7 @@ module ActiveRecord::Cloneable | |
| 115 117 | 
             
                      cloned_child_record = kids.build
         | 
| 116 118 | 
             
                      child_args = { cloned_parents: args[:cloned_parents] + [self],
         | 
| 117 119 | 
             
                                     attributes: {},
         | 
| 120 | 
            +
                                     stack: args[:stack] + [ child_relation.name ],
         | 
| 118 121 | 
             
                                     object: cloned_child_record,
         | 
| 119 122 | 
             
                                     skipped_parent_relations: find_applicable_clone_args( child_relation.name, args[:skipped_parent_relations] ),
         | 
| 120 123 | 
             
                                     shared_parent_relations: find_applicable_clone_args( child_relation.name, args[:shared_parent_relations] ),
         | 
| @@ -138,8 +141,10 @@ module ActiveRecord::Cloneable | |
| 138 141 | 
             
                    next if args[:skipped_children].include?( kid )
         | 
| 139 142 | 
             
                    cloned_child_record = kid.build
         | 
| 140 143 | 
             
                    child_args = { cloned_parents: args[:cloned_parents] + [self],
         | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 144 | 
            +
                                   attributes: {},
         | 
| 145 | 
            +
                                   object: cloned_child_record,
         | 
| 146 | 
            +
                                   stack: args[:stack] + [ child_relation.name ] ,
         | 
| 147 | 
            +
                                   skipped_child_relations: args[:skipped_child_relations].find_all{ |x| x.is_a?( Hash ) && x[child_relation.name.to_sym]  }.map{ |x| x.values }.flatten }
         | 
| 143 148 | 
             
                    begin
         | 
| 144 149 | 
             
                      cloned_child_record = kid.clone_record( child_args )
         | 
| 145 150 | 
             
                      cloned_record.send( "#{child_relation.name}=",  cloned_child_record )
         |