uid_attribute 0.2.7 → 0.3.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.
- data/.gitignore +8 -2
- data/Gemfile +3 -0
- data/LICENSE +20 -20
- data/README.rdoc +37 -37
- data/Rakefile +14 -38
- data/doc/UidAttribute.html +258 -0
- data/doc/UidAttribute/ClassMethods.html +194 -0
- data/doc/created.rid +3 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +57 -0
- data/doc/js/darkfish.js +116 -0
- data/doc/js/jquery.js +32 -0
- data/doc/js/quicksearch.js +114 -0
- data/doc/js/thickbox-compressed.js +10 -0
- data/doc/lib/uid_attribute/version_rb.html +54 -0
- data/doc/lib/uid_attribute_rb.html +56 -0
- data/doc/rdoc.css +763 -0
- data/lib/uid_attribute.rb +51 -22
- data/lib/uid_attribute/version.rb +5 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/uid_attribute_spec.rb +71 -0
- data/uid_attribute.gemspec +15 -43
- metadata +93 -50
- data/VERSION.yml +0 -5
- data/test/uid_attribute_test.rb +0 -25
data/lib/uid_attribute.rb
CHANGED
|
@@ -1,57 +1,86 @@
|
|
|
1
|
-
|
|
1
|
+
require "uid_attribute/version"
|
|
2
2
|
require 'uuidtools'
|
|
3
3
|
|
|
4
|
+
module UIDAttribute
|
|
5
|
+
|
|
4
6
|
def self.included( klass ) # :nodoc:
|
|
5
7
|
klass.extend ClassMethods
|
|
6
|
-
klass.install_uid_attribute
|
|
8
|
+
klass.send(:install_uid_attribute)
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
module ClassMethods
|
|
10
12
|
include UUIDTools
|
|
11
13
|
|
|
12
|
-
def install_uid_attribute #:nodoc:
|
|
13
|
-
uid_attribute
|
|
14
|
-
end
|
|
15
|
-
|
|
16
14
|
# :call-seq:
|
|
17
15
|
# uid_attribute
|
|
18
16
|
#
|
|
19
17
|
# This function defines the UID attribute for the klass <tt>(default: :uid)</tt>
|
|
20
18
|
|
|
21
19
|
def uid_attribute(uid_attr = :uid)
|
|
22
|
-
|
|
23
|
-
validates_uniqueness_of uid_attr
|
|
24
|
-
end
|
|
20
|
+
install_uid_attribute_validators(uid_attr)
|
|
25
21
|
|
|
26
22
|
class_eval("class << self;attr_accessor :uid_attr;attr_accessor :uid_object; end")
|
|
27
|
-
@uid_attr = uid_attr
|
|
28
23
|
@uid_object = false
|
|
24
|
+
protected
|
|
25
|
+
@uid_attr = uid_attr
|
|
29
26
|
end
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
protected
|
|
29
|
+
|
|
30
|
+
def install_uid_attribute #:nodoc:
|
|
31
|
+
uid_attribute
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# :call-seq:
|
|
35
|
+
# install_uid_attribute_validators :uid_attr
|
|
36
|
+
#
|
|
37
|
+
# if the including class inherits from ActiveRecord::Base,
|
|
38
|
+
# then validate Klass.uid_attr is not blank and is unique (within this model)
|
|
39
|
+
|
|
40
|
+
def install_uid_attribute_validators(uid_attr) #:nodoc:
|
|
41
|
+
return unless ancestors.collect{|ancestor|
|
|
42
|
+
ancestor.to_s }.include?('ActiveRecord::Base')
|
|
43
|
+
validates_presence_of uid_attr
|
|
44
|
+
validates_uniqueness_of uid_attr
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end # /class_methods
|
|
32
48
|
|
|
33
|
-
def initialize(args
|
|
34
|
-
|
|
49
|
+
def initialize(*args) # :nodoc:
|
|
50
|
+
# hyjack including class initializer to set UID too
|
|
51
|
+
ret = super(*args)
|
|
35
52
|
set_uid
|
|
53
|
+
ret
|
|
36
54
|
end
|
|
37
55
|
|
|
38
56
|
# :call-seq:
|
|
39
57
|
# set_uid
|
|
40
58
|
#
|
|
41
|
-
#
|
|
59
|
+
# set :uid_attribute
|
|
42
60
|
|
|
43
61
|
def set_uid
|
|
44
|
-
|
|
62
|
+
klass = self.class
|
|
63
|
+
has_uid_accessors?
|
|
45
64
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
else
|
|
49
|
-
uid = UUIDTools::UUID.random_create.to_s
|
|
50
|
-
end
|
|
65
|
+
uid = klass.uid_object ? UUIDTools::UUID.md5_create(UUIDTools::UUID_OID_NAMESPACE, self.inspect) :
|
|
66
|
+
UUIDTools::UUID.random_create.to_s
|
|
51
67
|
|
|
52
|
-
send("#{
|
|
68
|
+
send("#{klass.uid_attr}=", uid)
|
|
53
69
|
end
|
|
54
70
|
|
|
55
|
-
|
|
71
|
+
protected
|
|
72
|
+
|
|
73
|
+
# :call-seq:
|
|
74
|
+
# has_uid_accessors?
|
|
75
|
+
#
|
|
76
|
+
# raises errors unless the including class has a setter and getter for Klass.uid_attr
|
|
77
|
+
|
|
78
|
+
def has_uid_accessors?
|
|
79
|
+
klass = self.class
|
|
80
|
+
uid_attr = klass.uid_attr
|
|
81
|
+
raise "dev.error: #{klass}.respond_to?(:#{uid_attr}) == false" unless respond_to?(uid_attr)
|
|
82
|
+
raise "dev.error: #{klass}.respond_to?(:#{uid_attr}=) == false" unless respond_to?("#{uid_attr}=")
|
|
56
83
|
end
|
|
57
84
|
|
|
85
|
+
end # /module
|
|
86
|
+
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
begin; require 'cover_me'; rescue LoadError; end
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'rspec'
|
|
4
|
+
#require 'rr'
|
|
5
|
+
#require 'spec/rr' # not updated to rspec-2
|
|
6
|
+
|
|
7
|
+
begin; require 'database_cleaner'; rescue LoadError; end
|
|
8
|
+
|
|
9
|
+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
|
|
10
|
+
# order to ease the transition to Capybara we set the default here. If you'd
|
|
11
|
+
# prefer to use XPath just remove this line and adjust any selectors in your
|
|
12
|
+
# steps to use the XPath syntax.
|
|
13
|
+
# Capybara.default_selector = :css
|
|
14
|
+
|
|
15
|
+
RSpec.configure do |config|
|
|
16
|
+
# == Mock Framework
|
|
17
|
+
#
|
|
18
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
19
|
+
#
|
|
20
|
+
# config.mock_with :mocha
|
|
21
|
+
# config.mock_with :flexmock
|
|
22
|
+
# config.mock_with :rr
|
|
23
|
+
config.mock_with :mocha
|
|
24
|
+
end
|
|
25
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'uid_attribute'
|
|
3
|
+
require 'ap'
|
|
4
|
+
|
|
5
|
+
class Model
|
|
6
|
+
include UIDAttribute
|
|
7
|
+
attr_accessor :uid
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class ModelSpecifyingUID
|
|
11
|
+
include UIDAttribute
|
|
12
|
+
uid_attribute :my_uid
|
|
13
|
+
attr_accessor :my_uid
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class ReadOnlyModel
|
|
17
|
+
include UIDAttribute
|
|
18
|
+
attr_reader :uid
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'uid_attribute' do
|
|
22
|
+
describe 'generation of a unique ID attribute upon instantiation' do
|
|
23
|
+
it 'should default to use the :uid attribute of the including class' do
|
|
24
|
+
@model = Model.new
|
|
25
|
+
@model.should respond_to(:uid)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should allow specification of the :uid attribute by the including class' do
|
|
29
|
+
@model_specifying_uid = ModelSpecifyingUID.new
|
|
30
|
+
@model_specifying_uid.should respond_to(:my_uid)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should generate a random ID upon instantiation' do
|
|
34
|
+
@model = Model.new
|
|
35
|
+
@model.uid.should be_a(String)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should optionally generate a MD5-sum (as an :uid) upon instantiation' do
|
|
39
|
+
@model = Model.new
|
|
40
|
+
Model.uid_object = true
|
|
41
|
+
@model.uid = 'seed'
|
|
42
|
+
checksum = @model.set_uid
|
|
43
|
+
|
|
44
|
+
@model.uid = 'seed'
|
|
45
|
+
@model.set_uid
|
|
46
|
+
@model.uid.should == checksum
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context 'should raise an error if the including classes uid_attribute' do
|
|
50
|
+
it 'does not have a getter' do
|
|
51
|
+
Model.uid_attr = :test_uid
|
|
52
|
+
lambda { Model.new }.should raise_error(RuntimeError)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'does not have a setter' do
|
|
56
|
+
lambda { ReadOnlyModel.new }.should raise_error(RuntimeError)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe 'classes inheritting ActiveRecord' do
|
|
62
|
+
pending 'should add validations to the including model' do
|
|
63
|
+
@model = Model.new
|
|
64
|
+
@model_specifying_uid = ModelSpecifyingUID.new
|
|
65
|
+
debugger
|
|
66
|
+
true
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
data/uid_attribute.gemspec
CHANGED
|
@@ -1,53 +1,25 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
|
3
|
+
require 'uid_attribute/version'
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name
|
|
8
|
-
s.version
|
|
9
|
-
|
|
10
|
-
s.
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
6
|
+
s.name = 'uid_attribute'
|
|
7
|
+
s.version = UIDAttribute::VERSION
|
|
8
|
+
s.authors = ['Paul Belt']
|
|
9
|
+
s.email = ['paul.belt@gmail.com']
|
|
10
|
+
s.homepage = %q{http://github.com/belt/uid_attribute}
|
|
11
|
+
s.summary = %q{machina to automatically generate UIDs upon object instantiation}
|
|
13
12
|
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
13
|
|
|
15
14
|
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
15
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
16
|
+
s.rubyforge_project = 'uid_attribute'
|
|
17
|
+
|
|
18
|
+
s.files = `git ls-files`.split("\n")
|
|
19
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
|
20
|
+
s.require_paths = ['lib']
|
|
43
21
|
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
22
|
+
s.add_development_dependency 'rspec'
|
|
23
|
+
s.add_runtime_dependency 'uuidtools'
|
|
52
24
|
end
|
|
53
25
|
|
metadata
CHANGED
|
@@ -1,74 +1,117 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uid_attribute
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.0
|
|
5
|
+
prerelease:
|
|
5
6
|
platform: ruby
|
|
6
|
-
authors:
|
|
7
|
+
authors:
|
|
7
8
|
- Paul Belt
|
|
8
9
|
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
date: 2011-08-19 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rspec
|
|
16
|
+
requirement: &2161449260 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *2161449260
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
16
26
|
name: uuidtools
|
|
27
|
+
requirement: &2161448840 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
17
33
|
type: :runtime
|
|
18
|
-
|
|
19
|
-
version_requirements:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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: []
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *2161448840
|
|
36
|
+
description: ! 'Some projects are confined by regulations (or requirements) that demand
|
|
37
|
+
data can not be used to identify individuals. In such cases data must be scrubbed
|
|
38
|
+
i.e. identifiable object names must be removed before unauthorized users can see
|
|
39
|
+
said data. For example, when a developer needs to recreate a bug on their own system
|
|
40
|
+
that was reported by a customer using customer-specific data.
|
|
31
41
|
|
|
32
|
-
extensions: []
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
One method to do this is to use globally unique identifiers within the system to
|
|
44
|
+
identify any given object.'
|
|
45
|
+
email:
|
|
46
|
+
- paul.belt@gmail.com
|
|
47
|
+
executables: []
|
|
48
|
+
extensions: []
|
|
49
|
+
extra_rdoc_files: []
|
|
50
|
+
files:
|
|
37
51
|
- .gitignore
|
|
52
|
+
- Gemfile
|
|
38
53
|
- LICENSE
|
|
39
54
|
- README.rdoc
|
|
40
55
|
- Rakefile
|
|
41
|
-
-
|
|
56
|
+
- doc/UidAttribute.html
|
|
57
|
+
- doc/UidAttribute/ClassMethods.html
|
|
58
|
+
- doc/created.rid
|
|
59
|
+
- doc/images/brick.png
|
|
60
|
+
- doc/images/brick_link.png
|
|
61
|
+
- doc/images/bug.png
|
|
62
|
+
- doc/images/bullet_black.png
|
|
63
|
+
- doc/images/bullet_toggle_minus.png
|
|
64
|
+
- doc/images/bullet_toggle_plus.png
|
|
65
|
+
- doc/images/date.png
|
|
66
|
+
- doc/images/find.png
|
|
67
|
+
- doc/images/loadingAnimation.gif
|
|
68
|
+
- doc/images/macFFBgHack.png
|
|
69
|
+
- doc/images/package.png
|
|
70
|
+
- doc/images/page_green.png
|
|
71
|
+
- doc/images/page_white_text.png
|
|
72
|
+
- doc/images/page_white_width.png
|
|
73
|
+
- doc/images/plugin.png
|
|
74
|
+
- doc/images/ruby.png
|
|
75
|
+
- doc/images/tag_green.png
|
|
76
|
+
- doc/images/wrench.png
|
|
77
|
+
- doc/images/wrench_orange.png
|
|
78
|
+
- doc/images/zoom.png
|
|
79
|
+
- doc/index.html
|
|
80
|
+
- doc/js/darkfish.js
|
|
81
|
+
- doc/js/jquery.js
|
|
82
|
+
- doc/js/quicksearch.js
|
|
83
|
+
- doc/js/thickbox-compressed.js
|
|
84
|
+
- doc/lib/uid_attribute/version_rb.html
|
|
85
|
+
- doc/lib/uid_attribute_rb.html
|
|
86
|
+
- doc/rdoc.css
|
|
42
87
|
- lib/uid_attribute.rb
|
|
43
|
-
-
|
|
88
|
+
- lib/uid_attribute/version.rb
|
|
89
|
+
- spec/spec.opts
|
|
90
|
+
- spec/spec_helper.rb
|
|
91
|
+
- spec/uid_attribute_spec.rb
|
|
44
92
|
- uid_attribute.gemspec
|
|
45
|
-
has_rdoc: true
|
|
46
93
|
homepage: http://github.com/belt/uid_attribute
|
|
47
94
|
licenses: []
|
|
48
|
-
|
|
49
95
|
post_install_message:
|
|
50
|
-
rdoc_options:
|
|
51
|
-
|
|
52
|
-
require_paths:
|
|
96
|
+
rdoc_options: []
|
|
97
|
+
require_paths:
|
|
53
98
|
- lib
|
|
54
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
|
+
none: false
|
|
101
|
+
requirements:
|
|
102
|
+
- - ! '>='
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
|
+
none: false
|
|
107
|
+
requirements:
|
|
108
|
+
- - ! '>='
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
66
111
|
requirements: []
|
|
67
|
-
|
|
68
112
|
rubyforge_project: uid_attribute
|
|
69
|
-
rubygems_version: 1.
|
|
113
|
+
rubygems_version: 1.8.6
|
|
70
114
|
signing_key:
|
|
71
115
|
specification_version: 3
|
|
72
|
-
summary: machina to automatically generate
|
|
73
|
-
test_files:
|
|
74
|
-
- test/uid_attribute_test.rb
|
|
116
|
+
summary: machina to automatically generate UIDs upon object instantiation
|
|
117
|
+
test_files: []
|