autoguid 1.0 → 1.1
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 +5 -13
- data/lib/autoguid.rb +5 -6
- data/lib/autoguid/version.rb +1 -1
- data/lib/migrator.rb +19 -13
- data/lib/tasks/autoguid_tasks.rake +7 -4
- metadata +33 -31
- data/README.rdoc +0 -16
    
        checksums.yaml
    CHANGED
    
    | @@ -1,15 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
             | 
| 5 | 
            -
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                Y2E3MDA0NzEzYzM3M2ZjMGI0NThiMWFjMmViZTc4ZGU4OGI4ZDIwMw==
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: af2280da75d8e9c5a479b514b35ccee3a014d426
         | 
| 4 | 
            +
              data.tar.gz: a493c4f4373a8f222b1b7e5a480dd44669061d32
         | 
| 7 5 | 
             
            SHA512:
         | 
| 8 | 
            -
              metadata.gz:  | 
| 9 | 
            -
             | 
| 10 | 
            -
                NjgwNjRiNGNjNTk0OTU3NmRhMDg0MjExM2Q2YmE3ZmU4NDdkZDQ0M2U3NTU5
         | 
| 11 | 
            -
                ZjVlMzA0MjBkOTdjOWExYTk1YTRiNTRhYWNhNDgxNGFmYmFhYmU=
         | 
| 12 | 
            -
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                M2YwOTVkMDAzYjc1Mjc2ZTM3NzNkYjRhMWYzYWNhNzczMDA3OTdlYTI3NTVk
         | 
| 14 | 
            -
                M2RhYWM2NTE0MzhmMDlhNTk5OWFlMDlkOWQ1ZWY1YjQxNTQ3Y2JmZGNlZDI2
         | 
| 15 | 
            -
                OTU0MmNjMjJiZTg4MDYxYjRjZjViMTk0MWJkMGM2MDQ5MzA5MzE=
         | 
| 6 | 
            +
              metadata.gz: f38b763ce1e947d4e7685b4876be1b54d275e704e44bb1925711b35dcd567357f6525a030802d6874bcef5750a2a9d910c2d848a82ccf965f08e01401b63e5c2
         | 
| 7 | 
            +
              data.tar.gz: fdf4aa27999fe6aacce17704ce347d28ccfe66ebba4473ab46c42a7cb3c9b5f941c7257997c6420d72e59cc5307dcbe66e0dc4e5fd2bb4cf2255a1d1fed7ac46
         | 
    
        data/lib/autoguid.rb
    CHANGED
    
    | @@ -14,16 +14,15 @@ module Autoguid | |
| 14 14 | 
             
                end
         | 
| 15 15 |  | 
| 16 16 | 
             
                def generate_autoguid
         | 
| 17 | 
            -
                  uuid = SecureRandom.uuid
         | 
| 18 17 | 
             
                  name = self.is_a?(Module) ? name : self.class.name
         | 
| 19 | 
            -
                  return name + '-' + uuid
         | 
| 18 | 
            +
                  return name + '-' + SecureRandom.uuid
         | 
| 20 19 | 
             
                end
         | 
| 21 20 |  | 
| 22 | 
            -
                def backfill(model)
         | 
| 23 | 
            -
                  puts  | 
| 21 | 
            +
                def self.backfill(model)
         | 
| 22 | 
            +
                  puts 'Backfilling ' + model.name
         | 
| 24 23 | 
             
                  model.all.each do |row|
         | 
| 25 | 
            -
                    puts  | 
| 26 | 
            -
                    row.guid = generate_autoguid
         | 
| 24 | 
            +
                    puts 'Updating a record'
         | 
| 25 | 
            +
                    row.guid = row.generate_autoguid
         | 
| 27 26 | 
             
                    row.save
         | 
| 28 27 | 
             
                  end
         | 
| 29 28 | 
             
                end
         | 
    
        data/lib/autoguid/version.rb
    CHANGED
    
    
    
        data/lib/migrator.rb
    CHANGED
    
    | @@ -3,28 +3,23 @@ class Migrator < ActiveRecord::Migration | |
| 3 3 | 
             
                attr_accessor :config
         | 
| 4 4 |  | 
| 5 5 | 
             
                def up
         | 
| 6 | 
            -
                  puts config
         | 
| 7 | 
            -
                   | 
| 8 | 
            -
                   | 
| 9 | 
            -
                  whitelist = Array.new
         | 
| 10 | 
            -
                  if ( @config[:all] )
         | 
| 11 | 
            -
                    whitelist = ActiveRecord::Base.direct_descendants if @config[:all]
         | 
| 12 | 
            -
                  elsif ( @config[:whitelist] )
         | 
| 6 | 
            +
                  puts 'Found config' + config.to_s
         | 
| 7 | 
            +
                  whitelist = Migrator.all_models if @config[:all] or @config[:blacklist]
         | 
| 8 | 
            +
                  if ( @config[:whitelist] )
         | 
| 13 9 | 
             
                    puts "Got into Whitelist"
         | 
| 14 | 
            -
                     | 
| 15 | 
            -
                     | 
| 10 | 
            +
                    whitelist = Array.new
         | 
| 11 | 
            +
                    Migrator.all_models.each do |m|
         | 
| 16 12 | 
             
                      puts "Checking for model " + m.name + " in whitelist "
         | 
| 17 13 | 
             
                      whitelist.push(m) if @config[:whitelist].include?(m.name)
         | 
| 18 14 | 
             
                    end
         | 
| 19 15 | 
             
                  elsif ( @config[:blacklist] )
         | 
| 20 16 | 
             
                    puts "Processing by blacklist"
         | 
| 21 | 
            -
                    whitelist = ActiveRecord::Base.direct_descendants
         | 
| 22 17 | 
             
                    whitelist.each do |m|
         | 
| 23 18 | 
             
                      puts "Checking for model " + m.name + " in blacklist "
         | 
| 24 19 | 
             
                      whitelist.delete(m) if @config[:blacklist].include?(m.name)
         | 
| 25 20 | 
             
                    end
         | 
| 26 21 | 
             
                  end
         | 
| 27 | 
            -
                  puts whitelist
         | 
| 22 | 
            +
                  puts "whitelist"
         | 
| 28 23 | 
             
                  whitelist.each do |model|
         | 
| 29 24 | 
             
                    puts "Processing " + model.name
         | 
| 30 25 | 
             
                    model.reset_column_information
         | 
| @@ -34,12 +29,23 @@ class Migrator < ActiveRecord::Migration | |
| 34 29 | 
             
                end
         | 
| 35 30 |  | 
| 36 31 | 
             
                def down
         | 
| 37 | 
            -
                   | 
| 38 | 
            -
                  ActiveRecord::Base.direct_descendants.each do |model|
         | 
| 32 | 
            +
                  Migrator.all_models.each do |model|
         | 
| 39 33 | 
             
                    model.reset_column_information
         | 
| 40 34 | 
             
                    remove_index(model, :guid) if index_exists?(model, :guid)
         | 
| 41 35 | 
             
                    remove_column(model, :guid) if column_exists?(model, :guid)
         | 
| 42 36 | 
             
                  end
         | 
| 43 37 | 
             
                end
         | 
| 44 38 |  | 
| 39 | 
            +
                def self.all_models
         | 
| 40 | 
            +
                  Rails.application.eager_load!
         | 
| 41 | 
            +
                  mods = Array.new
         | 
| 42 | 
            +
                  Module.constants.select do |constant_name|
         | 
| 43 | 
            +
                    constant = eval( constant_name.to_s )
         | 
| 44 | 
            +
                    if not constant.nil? and constant.is_a? Class and constant.superclass == ActiveRecord::Base
         | 
| 45 | 
            +
                      mods.push(constant)
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                  return mods
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 45 51 | 
             
            end
         | 
| @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            namespace :autoguid do
         | 
| 2 2 | 
             
            	task :install do
         | 
| 3 | 
            +
                puts 'Copying autoguid initializer to your app'
         | 
| 3 4 | 
             
                path = Rails.root.to_s + "/config/initializers/autoguid.rb"
         | 
| 4 5 | 
             
                template_path = File.expand_path('../../initializer.rb',__FILE__)
         | 
| 5 6 | 
             
                template = File.open(template_path)
         | 
| @@ -9,20 +10,22 @@ namespace :autoguid do | |
| 9 10 | 
             
            	end
         | 
| 10 11 | 
             
              namespace :migrate do
         | 
| 11 12 | 
             
                task :up => :environment do
         | 
| 13 | 
            +
                  'Migrating database up for autoguids'
         | 
| 12 14 | 
             
                  init = Initializer.new
         | 
| 13 15 | 
             
                  init.config
         | 
| 14 16 | 
             
                  init.up
         | 
| 15 17 | 
             
                end
         | 
| 16 | 
            -
                task :drop_all => :environment do
         | 
| 18 | 
            +
                task :drop_all => :environment do  
         | 
| 19 | 
            +
                  'Dropping all autoguids'
         | 
| 17 20 | 
             
                  init = Initializer.new
         | 
| 18 21 | 
             
                  init.config
         | 
| 19 22 | 
             
                  init.drop_all
         | 
| 20 23 | 
             
                end
         | 
| 21 24 | 
             
                task :backfill => :environment do
         | 
| 25 | 
            +
                  puts 'Backfilling all autoguids'
         | 
| 22 26 | 
             
                  require 'autoguid'
         | 
| 23 | 
            -
                   | 
| 24 | 
            -
             | 
| 25 | 
            -
                    puts model
         | 
| 27 | 
            +
                  Migrator.all_models.each do |model|
         | 
| 28 | 
            +
                    puts 'Backfilling: ' + model.name
         | 
| 26 29 | 
             
                    model.reset_column_information
         | 
| 27 30 | 
             
                    Autoguid.backfill(model) if model.columns_hash['guid']
         | 
| 28 31 | 
             
                  end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,105 +1,108 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: autoguid
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: '1. | 
| 4 | 
            +
              version: '1.1'
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Peter Kinnaird
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-09- | 
| 11 | 
            +
            date: 2014-09-24 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - ~>
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: 4.1.4
         | 
| 20 | 
            -
                - -  | 
| 20 | 
            +
                - - ">="
         | 
| 21 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 22 22 | 
             
                    version: 4.1.4
         | 
| 23 23 | 
             
              type: :runtime
         | 
| 24 24 | 
             
              prerelease: false
         | 
| 25 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 26 | 
             
                requirements:
         | 
| 27 | 
            -
                - - ~>
         | 
| 27 | 
            +
                - - "~>"
         | 
| 28 28 | 
             
                  - !ruby/object:Gem::Version
         | 
| 29 29 | 
             
                    version: 4.1.4
         | 
| 30 | 
            -
                - -  | 
| 30 | 
            +
                - - ">="
         | 
| 31 31 | 
             
                  - !ruby/object:Gem::Version
         | 
| 32 32 | 
             
                    version: 4.1.4
         | 
| 33 33 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 34 34 | 
             
              name: rake
         | 
| 35 35 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 36 36 | 
             
                requirements:
         | 
| 37 | 
            -
                - - ~>
         | 
| 37 | 
            +
                - - "~>"
         | 
| 38 38 | 
             
                  - !ruby/object:Gem::Version
         | 
| 39 39 | 
             
                    version: 10.1.0
         | 
| 40 | 
            -
                - -  | 
| 40 | 
            +
                - - ">="
         | 
| 41 41 | 
             
                  - !ruby/object:Gem::Version
         | 
| 42 42 | 
             
                    version: 10.1.0
         | 
| 43 43 | 
             
              type: :development
         | 
| 44 44 | 
             
              prerelease: false
         | 
| 45 45 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 46 46 | 
             
                requirements:
         | 
| 47 | 
            -
                - - ~>
         | 
| 47 | 
            +
                - - "~>"
         | 
| 48 48 | 
             
                  - !ruby/object:Gem::Version
         | 
| 49 49 | 
             
                    version: 10.1.0
         | 
| 50 | 
            -
                - -  | 
| 50 | 
            +
                - - ">="
         | 
| 51 51 | 
             
                  - !ruby/object:Gem::Version
         | 
| 52 52 | 
             
                    version: 10.1.0
         | 
| 53 53 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 54 54 | 
             
              name: rspec
         | 
| 55 55 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 56 56 | 
             
                requirements:
         | 
| 57 | 
            -
                - - ~>
         | 
| 57 | 
            +
                - - "~>"
         | 
| 58 58 | 
             
                  - !ruby/object:Gem::Version
         | 
| 59 59 | 
             
                    version: 3.0.0
         | 
| 60 | 
            -
                - -  | 
| 60 | 
            +
                - - ">="
         | 
| 61 61 | 
             
                  - !ruby/object:Gem::Version
         | 
| 62 62 | 
             
                    version: 3.0.0
         | 
| 63 63 | 
             
              type: :development
         | 
| 64 64 | 
             
              prerelease: false
         | 
| 65 65 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 66 66 | 
             
                requirements:
         | 
| 67 | 
            -
                - - ~>
         | 
| 67 | 
            +
                - - "~>"
         | 
| 68 68 | 
             
                  - !ruby/object:Gem::Version
         | 
| 69 69 | 
             
                    version: 3.0.0
         | 
| 70 | 
            -
                - -  | 
| 70 | 
            +
                - - ">="
         | 
| 71 71 | 
             
                  - !ruby/object:Gem::Version
         | 
| 72 72 | 
             
                    version: 3.0.0
         | 
| 73 73 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 74 74 | 
             
              name: sqlite3
         | 
| 75 75 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 76 76 | 
             
                requirements:
         | 
| 77 | 
            -
                - - ~>
         | 
| 77 | 
            +
                - - "~>"
         | 
| 78 78 | 
             
                  - !ruby/object:Gem::Version
         | 
| 79 79 | 
             
                    version: 1.3.9
         | 
| 80 | 
            -
                - -  | 
| 80 | 
            +
                - - ">="
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 82 | 
             
                    version: 1.3.9
         | 
| 83 83 | 
             
              type: :development
         | 
| 84 84 | 
             
              prerelease: false
         | 
| 85 85 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
                requirements:
         | 
| 87 | 
            -
                - - ~>
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 89 | 
             
                    version: 1.3.9
         | 
| 90 | 
            -
                - -  | 
| 90 | 
            +
                - - ">="
         | 
| 91 91 | 
             
                  - !ruby/object:Gem::Version
         | 
| 92 92 | 
             
                    version: 1.3.9
         | 
| 93 | 
            -
            description:  | 
| 94 | 
            -
               | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 102 | 
            -
             | 
| 93 | 
            +
            description: |-
         | 
| 94 | 
            +
              Autoguid lets you trivially add human readable uuids to all
         | 
| 95 | 
            +
                 your models, a whitelisted set of models, or a blacklisted set.
         | 
| 96 | 
            +
                 Indices are automatically created based on a configuration option.
         | 
| 97 | 
            +
                 There's also a rake task that will backfill these uuids into resources that
         | 
| 98 | 
            +
                 have already been created.
         | 
| 99 | 
            +
                 To get started, include the gem file, run `bundle install`, then run
         | 
| 100 | 
            +
                 `rake autoguid:install`. From there, edit the config/initializers/autoguid.rb
         | 
| 101 | 
            +
                 file to specifcy your configuration. Next, migrate your tables with
         | 
| 102 | 
            +
                 `rake autoguid:migrate:up` and `rake autoguid:migrate:backfill` as required.
         | 
| 103 | 
            +
                 `rake autoguid:migrate:drop_all` will drop all autoguid generated columns and
         | 
| 104 | 
            +
                 the data in them. You can always change the config/initializers/autoguid.rb file
         | 
| 105 | 
            +
                 and rerun `rake autoguid:migrate:up` to add autoguid to new models.
         | 
| 103 106 | 
             
            email:
         | 
| 104 107 | 
             
            - peter@hacktivism.cc
         | 
| 105 108 | 
             
            executables: []
         | 
| @@ -107,7 +110,6 @@ extensions: [] | |
| 107 110 | 
             
            extra_rdoc_files: []
         | 
| 108 111 | 
             
            files:
         | 
| 109 112 | 
             
            - MIT-LICENSE
         | 
| 110 | 
            -
            - README.rdoc
         | 
| 111 113 | 
             
            - Rakefile
         | 
| 112 114 | 
             
            - lib/autoguid.rb
         | 
| 113 115 | 
             
            - lib/autoguid/version.rb
         | 
| @@ -125,12 +127,12 @@ require_paths: | |
| 125 127 | 
             
            - lib
         | 
| 126 128 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 127 129 | 
             
              requirements:
         | 
| 128 | 
            -
              - -  | 
| 130 | 
            +
              - - ">="
         | 
| 129 131 | 
             
                - !ruby/object:Gem::Version
         | 
| 130 132 | 
             
                  version: '0'
         | 
| 131 133 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 132 134 | 
             
              requirements:
         | 
| 133 | 
            -
              - -  | 
| 135 | 
            +
              - - ">="
         | 
| 134 136 | 
             
                - !ruby/object:Gem::Version
         | 
| 135 137 | 
             
                  version: '0'
         | 
| 136 138 | 
             
            requirements: []
         | 
    
        data/README.rdoc
    DELETED
    
    | @@ -1,16 +0,0 @@ | |
| 1 | 
            -
            = Autoguid
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            This project rocks and uses MIT-LICENSE.
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            Autoguid lets you trivially add human readable uuids to all
         | 
| 6 | 
            -
            your models, a whitelisted set of models, or all but a blacklisted set.
         | 
| 7 | 
            -
            Indices are automatically created based on a configuration option.
         | 
| 8 | 
            -
            There's also a rake task that will backfill these uuids into resources that
         | 
| 9 | 
            -
            have already been created.
         | 
| 10 | 
            -
            To get started, include the gem file, run `bundle install`, then run
         | 
| 11 | 
            -
            `rake autoguid:install`. From there, edit the config/initializers/autoguid.rb
         | 
| 12 | 
            -
            file to specify your configuration. Next, migrate your tables with
         | 
| 13 | 
            -
            `rake autoguid:migrate:up` and `rake autoguid:migrate:backfill` as required.
         | 
| 14 | 
            -
            `rake autoguid:migrate:drop_all` will drop all autoguid generated columns and
         | 
| 15 | 
            -
            the data in them. You can always change the config/initializers/autoguid.rb file
         | 
| 16 | 
            -
            and rerun `rake autoguid:migrate:up` to add autoguid to new models.
         |