delynn-uuid_fu 1.0.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.
@@ -0,0 +1,68 @@
1
+ require 'uuid'
2
+
3
+ if defined?(UUID) && defined?(UUID::VERSION) && UUID::VERSION == '2.0.1'
4
+ module UuidFu
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ # Identify which columns should use a Universally Unique Identifier, along with the UUID format. Available
11
+ # formats are <tt>:default</tt>, <tt>:compressed</tt>, and <tt>:urn</tt>. The plug-in actually defaults
12
+ # to using the <tt>:compressed</tt> format as the default since it doesn't include dashes.
13
+ #
14
+ # === Examples
15
+ #
16
+ # # A new User instance will have the <tt>id</tt> attribute set to a UUID with the <tt>:compressed</tt>
17
+ # # format.
18
+ # class User < ActiveRecord::Base
19
+ # uniquely_identified_by(:id)
20
+ # end
21
+ #
22
+ # # A new User instance will have all the attributes set to a UUID with the <tt>:default</tt>
23
+ # # format.
24
+ # class User < ActiveRecord::Base
25
+ # uniquely_identified_by(:id, :other, :uuid_format => :default)
26
+ # end
27
+ #
28
+ # # A new User instance will have the <tt>:id</tt> attribute set to a UUID with the <tt>:default</tt>
29
+ # # format, the <tt>:other</tt> attribute will be set to a UUID with the <tt>:urn</tt> format, and
30
+ # # the <tt>:last</tt> attribute will be set to a UUID with the <tt>:compressed</tt> format.
31
+ # class User < ActiveRecord::Base
32
+ # uniquely_identified_by(:id => :default, :other => :urn, :last => :compressed)
33
+ # end
34
+ def uniquely_identified_by(*args)
35
+ cattr_accessor :uniquely_identified_columns
36
+ cattr_accessor :format_for_uniquely_identified_columns
37
+
38
+ columns_and_formats = args.extract_options!
39
+ if columns_and_formats.empty?
40
+ self.format_for_uniquely_identified_columns = :compact
41
+ self.uniquely_identified_columns = [args].flatten
42
+ elsif columns_and_formats.include?(:uuid_format)
43
+ self.format_for_uniquely_identified_columns = columns_and_formats.delete(:uuid_format)
44
+ self.uniquely_identified_columns = [args].flatten
45
+ else
46
+ self.uniquely_identified_columns = columns_and_formats
47
+ end
48
+
49
+ self.class_eval do
50
+ def before_create_with_uuid
51
+ before_create_without_uuid
52
+ self.uniquely_identified_columns.each do |column, format|
53
+ format ||= self.format_for_uniquely_identified_columns
54
+ uuid = UUID.generate(format)
55
+ self.send("#{column}=".to_sym, uuid)
56
+ end
57
+ end
58
+
59
+ alias_method_chain :before_create, :uuid
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ ActiveRecord::Base.send(:include, UuidFu)
66
+ else
67
+ raise "This plug-in is only compatible with version 2.0.1 of the following UUID gem: http://github.com/assaf/uuid"
68
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delynn-uuid_fu
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - DeLynn Berry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-25 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "Developed by: delynn@gmail.com"
17
+ email: delynn@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - lib/uuid_fu/schema_statements.rb
26
+ - lib/uuid_fu/uuid_fu.rb
27
+ - lib/uuid_fu.rb
28
+ - README
29
+ - doc/classes/UuidFu/ClassMethods.html
30
+ - doc/classes/UuidFu/SchemaStatements/InstanceMethods.html
31
+ - doc/classes/UuidFu/SchemaStatements.html
32
+ - doc/classes/UuidFu.html
33
+ - doc/created.rid
34
+ - doc/files/lib/uuid_fu/schema_statements_rb.html
35
+ - doc/files/lib/uuid_fu/uuid_fu_rb.html
36
+ - doc/files/lib/uuid_fu_rb.html
37
+ - doc/files/README.html
38
+ - doc/fr_class_index.html
39
+ - doc/fr_file_index.html
40
+ - doc/fr_method_index.html
41
+ - doc/index.html
42
+ - doc/rdoc-style.css
43
+ has_rdoc: true
44
+ homepage: http://delynnberry.com
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project: uuid_fu
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: A gem that helps out with using UUIDs for primary keys in ActiveRecord objects.
69
+ test_files: []
70
+