uid_attribute 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ rdoc
2
+ coverage
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [Paul Belt]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
20
+
data/README.rdoc ADDED
@@ -0,0 +1,37 @@
1
+ = UidAttribute -- Globally Unique Identifiable Attributes
2
+
3
+ machina to automatically generate UUIDs upon object instantiation.
4
+
5
+
6
+ == Example
7
+
8
+ require File.join(File.dirname(__FILE__),'lib','uid_attribute')
9
+
10
+ class MyObject
11
+ include UIDAttribute
12
+
13
+ attr_accessor :uid
14
+ uid_attribute :uid # this is optional e.g. to change the UID attribute
15
+ end
16
+
17
+ puts MyObject.new.uid
18
+ # => 4981a86e-239c-45dd-b4b3-283c435fb8ad
19
+
20
+ == Use case
21
+
22
+ Some projects are confined by regulations (or requirements) that demand data can not be used to identify individuals. In such cases data must be scrubbed i.e. identifiable object names must be removed before unauthorized users can see said data. For example, when a developer needs to recreate a bug on their own system that was reported by a customer using customer-specific data.
23
+
24
+ One method to do this is to use globally unique identifiers within the system to identify any given object.
25
+
26
+ == Installation
27
+
28
+ % script/plugin install git://github.com/belt/uid_attribute.git
29
+
30
+ == License
31
+
32
+ Copyright (c) 2010 [Paul Belt], released under the MIT license
33
+
34
+ == Support
35
+
36
+ http://github.com/belt/uid_attribute
37
+
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the uid_attribute plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the uid_attribute plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'UidAttribute'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |gemspec|
28
+ gemspec.name = 'uid_attribute'
29
+ gemspec.summary = 'machina to automatically generate UUIDs upon object instantiation.'
30
+ gemspec.description = "Some projects are confined by regulations (or requirements) that demand data can not be used to identify individuals. In such cases data must be scrubbed i.e. identifiable object names must be removed before unauthorized users can see said data. For example, when a developer needs to recreate a bug on their own system that was reported by a customer using customer-specific data.\n\nOne method to do this is to use globally unique identifiers within the system to identify any given object."
31
+ gemspec.email = 'Paul Belt'
32
+ gemspec.authors = ['Paul Belt']
33
+ gemspec.homepage = 'http://github.com/belt/uid_attribute'
34
+ gemspec.extra_rdoc_files = ['README.rdoc']
35
+ gemspec.rdoc_options = ['--charset=UTF-8']
36
+ gemspec.add_dependency('uuidtools', '>= 2.1.1')
37
+ gemspec.rubyforge_project = 'uid_attribute'
38
+ end
39
+ rescue LoadError
40
+ puts "Jeweler not available. Install it with: gem install jeweler"
41
+ end
42
+
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :minor: 2
3
+ :patch: 7
4
+ :build:
5
+ :major: 0
@@ -0,0 +1,57 @@
1
+ module UIDAttribute
2
+ require 'uuidtools'
3
+
4
+ def self.included( klass ) # :nodoc:
5
+ klass.extend ClassMethods
6
+ klass.install_uid_attribute
7
+ end
8
+
9
+ module ClassMethods
10
+ include UUIDTools
11
+
12
+ def install_uid_attribute #:nodoc:
13
+ uid_attribute
14
+ end
15
+
16
+ # :call-seq:
17
+ # uid_attribute
18
+ #
19
+ # This function defines the UID attribute for the klass <tt>(default: :uid)</tt>
20
+
21
+ def uid_attribute(uid_attr = :uid)
22
+ if ancestors.include?('ActiveRecord::Base')
23
+ validates_uniqueness_of uid_attr
24
+ end
25
+
26
+ class_eval("class << self;attr_accessor :uid_attr;attr_accessor :uid_object; end")
27
+ @uid_attr = uid_attr
28
+ @uid_object = false
29
+ end
30
+
31
+ end
32
+
33
+ def initialize(args = {}) # :nodoc:
34
+ args.empty? ? super() : super(args)
35
+ set_uid
36
+ end
37
+
38
+ # :call-seq:
39
+ # set_uid
40
+ #
41
+ # This function sets the attribute (as identified by klass.uid_attribute)
42
+
43
+ def set_uid
44
+ raise "dev.error: #{self.class}.respond_to?(:#{self.class.uid_attr}) == false" unless respond_to?(self.class.uid_attr)
45
+
46
+ if self.class.uid_object
47
+ uid = UUIDTools::UUID.md5_create(UUIDTools::UUID_OID_NAMESPACE, "#{self.inspect}")
48
+ else
49
+ uid = UUIDTools::UUID.random_create.to_s
50
+ end
51
+
52
+ send("#{self.class.uid_attr}=", uid)
53
+ end
54
+
55
+ # /module
56
+ end
57
+
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require File.join(File.dirname(__FILE__),'..','lib','uid_attribute')
4
+
5
+ class Model
6
+ include UIDAttribute
7
+ attr_accessor :uid
8
+ end
9
+
10
+ class UidAttribueTest < Test::Unit::TestCase
11
+ def setup
12
+ @model = Model.new
13
+ assert @model.class.uid_attr
14
+ end
15
+
16
+ def test_uid_attr
17
+ assert !@model.send(@model.class.uid_attr).nil?
18
+ end
19
+
20
+ def test_object_uid_attr
21
+ Model.uid_object = true
22
+ assert !@model.send(@model.class.uid_attr).nil?
23
+ end
24
+ end
25
+
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{uid_attribute}
8
+ s.version = "0.2.7"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Paul Belt"]
12
+ s.date = %q{2010-05-06}
13
+ s.description = %q{Some projects are confined by regulations (or requirements) that demand data can not be used to identify individuals. In such cases data must be scrubbed i.e. identifiable object names must be removed before unauthorized users can see said data. For example, when a developer needs to recreate a bug on their own system that was reported by a customer using customer-specific data.
14
+
15
+ One method to do this is to use globally unique identifiers within the system to identify any given object.}
16
+ s.email = %q{Paul Belt}
17
+ s.extra_rdoc_files = [
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION.yml",
26
+ "lib/uid_attribute.rb",
27
+ "test/uid_attribute_test.rb",
28
+ "uid_attribute.gemspec"
29
+ ]
30
+ s.homepage = %q{http://github.com/belt/uid_attribute}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubyforge_project = %q{uid_attribute}
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{machina to automatically generate UUIDs upon object instantiation.}
36
+ s.test_files = [
37
+ "test/uid_attribute_test.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<uuidtools>, [">= 2.1.1"])
46
+ else
47
+ s.add_dependency(%q<uuidtools>, [">= 2.1.1"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<uuidtools>, [">= 2.1.1"])
51
+ end
52
+ end
53
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uid_attribute
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.7
5
+ platform: ruby
6
+ authors:
7
+ - Paul Belt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-05-06 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: uuidtools
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.1
24
+ version:
25
+ description: |-
26
+ Some projects are confined by regulations (or requirements) that demand data can not be used to identify individuals. In such cases data must be scrubbed i.e. identifiable object names must be removed before unauthorized users can see said data. For example, when a developer needs to recreate a bug on their own system that was reported by a customer using customer-specific data.
27
+
28
+ One method to do this is to use globally unique identifiers within the system to identify any given object.
29
+ email: Paul Belt
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - README.rdoc
36
+ files:
37
+ - .gitignore
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION.yml
42
+ - lib/uid_attribute.rb
43
+ - test/uid_attribute_test.rb
44
+ - uid_attribute.gemspec
45
+ has_rdoc: true
46
+ homepage: http://github.com/belt/uid_attribute
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: uid_attribute
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: machina to automatically generate UUIDs upon object instantiation.
73
+ test_files:
74
+ - test/uid_attribute_test.rb