sets_uuid 0.1.1 → 1.0.0

This diff has not been reviewed by any users.
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ 1.0.0 :: Switching to simple_uuid gem (because it is... simpler, and
2
+ does not use a file for persisting state)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Emmanuel Oga
1
+ Copyright (c) 2009, 2010 Emmanuel Oga
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -2,14 +2,16 @@
2
2
 
3
3
  Allows you to declaratively initialize UUID columns in your ActiveRecords.
4
4
 
5
- class MyModel < ActiveRecord::Base
5
+ class MyModel < ActiveRecord::Base
6
+ sets_uuid :before_create, :guid => :compact
7
+ end
6
8
 
7
- sets_uuid :before_create, :guid => :compact
9
+ m = MyModel.create!
10
+ m.guid # => "a80cca5469254331a2f7df23da2b837f"
8
11
 
9
- end
10
-
11
- m = MyModel.create!
12
- m.guid # => "a80cca54-6925-4331-a2f7-df23da2b837f"
12
+ This gem requires the simple_uuid gem. The reason I picked this library instead
13
+ of the classic uuid gem is because the later does not use a state file, which I
14
+ find annoying in some situations.
13
15
 
14
16
  == Note on Patches/Pull Requests
15
17
 
data/Rakefile CHANGED
@@ -1,26 +1,49 @@
1
- require 'rubygems'
2
1
  require 'rake'
2
+ require 'date'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "sets_uuid"
8
- gem.summary = %Q{Adds declarative uuid attribute initialization to models}
9
- gem.description = %Q{UUID management for models}
10
- gem.email = "EmmanuelOga@gmail.com"
11
- gem.homepage = "http://github.com/EmmanuelOga/sets_uuid"
12
- gem.authors = ["Emmanuel Oga"]
13
- gem.add_development_dependency "rspec"
14
- gem.add_dependency "uuid"
15
- gem.add_dependency "activerecord"
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
4
+ #############################################################################
5
+ #
6
+ # Helper functions
7
+ #
8
+ #############################################################################
9
+
10
+ def name
11
+ @name ||= Dir['*.gemspec'].first.split('.').first
12
+ end
13
+
14
+ def version
15
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
16
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
17
+ end
18
+
19
+ def date
20
+ Date.today.to_s
21
+ end
22
+
23
+ def rubyforge_project
24
+ name
21
25
  end
22
26
 
27
+ def gemspec_file
28
+ "#{name}.gemspec"
29
+ end
30
+
31
+ def gem_file
32
+ "#{name}-#{version}.gem"
33
+ end
34
+
35
+ def replace_header(head, header_name)
36
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
37
+ end
38
+
39
+ #############################################################################
40
+ #
41
+ # Standard tasks
42
+ #
43
+ #############################################################################
44
+
23
45
  require 'spec/rake/spectask'
46
+
24
47
  Spec::Rake::SpecTask.new(:spec) do |spec|
25
48
  spec.libs << 'lib' << 'spec'
26
49
  spec.spec_files = FileList['spec/**/*_spec.rb']
@@ -32,20 +55,88 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
32
55
  spec.rcov = true
33
56
  end
34
57
 
35
- task :spec => :check_dependencies
36
-
37
58
  task :default => :spec
38
59
 
39
- require 'rake/rdoctask'
40
- Rake::RDocTask.new do |rdoc|
41
- if File.exist?('VERSION')
42
- version = File.read('VERSION')
43
- else
44
- version = ""
60
+ desc "Open an irb session preloaded with this library"
61
+ task :console do
62
+ sh "irb -rubygems -r ./lib/#{name}.rb"
63
+ end
64
+
65
+ #############################################################################
66
+ #
67
+ # Custom tasks (add your own tasks here)
68
+ #
69
+ #############################################################################
70
+
71
+ begin
72
+ require 'yard'
73
+ YARD::Rake::YardocTask.new
74
+ rescue LoadError
75
+ task :yardoc do
76
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
45
77
  end
78
+ end
79
+
80
+ #############################################################################
81
+ #
82
+ # Packaging tasks
83
+ #
84
+ #############################################################################
85
+
86
+ task :release => :build do
87
+ unless `git branch` =~ /^\* master$/
88
+ puts "You must be on the master branch to release!"
89
+ exit!
90
+ end
91
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
92
+ sh "git tag v#{version}"
93
+ sh "git push origin master"
94
+ sh "git push --tags"
95
+ sh "gem push pkg/#{name}-#{version}.gem"
96
+ end
46
97
 
47
- rdoc.rdoc_dir = 'rdoc'
48
- rdoc.title = "sets_uuid #{version}"
49
- rdoc.rdoc_files.include('README*')
50
- rdoc.rdoc_files.include('lib/**/*.rb')
98
+ task :build => :gemspec do
99
+ sh "mkdir -p pkg"
100
+ sh "gem build #{gemspec_file}"
101
+ sh "mv #{gem_file} pkg"
102
+ end
103
+
104
+ task :gemspec => :validate do
105
+ # read spec file and split out manifest section
106
+ spec = File.read(gemspec_file)
107
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
108
+
109
+ # replace name version and date
110
+ replace_header(head, :name)
111
+ replace_header(head, :version)
112
+ replace_header(head, :date)
113
+ #comment this out if your rubyforge_project has a different name
114
+ replace_header(head, :rubyforge_project)
115
+
116
+ # determine file list from git ls-files
117
+ files = `git ls-files`.
118
+ split("\n").
119
+ sort.
120
+ reject { |file| file =~ /^\./ }.
121
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
122
+ map { |file| " #{file}" }.
123
+ join("\n")
124
+
125
+ # piece file back together and write
126
+ manifest = " s.files = %w[\n#{files}\n ]\n"
127
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
128
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
129
+ puts "Updated #{gemspec_file}"
130
+ end
131
+
132
+ task :validate do
133
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
134
+ unless libfiles.empty?
135
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
136
+ exit!
137
+ end
138
+ unless Dir['VERSION*'].empty?
139
+ puts "A `VERSION` file at root level violates Gem best practices."
140
+ exit!
141
+ end
51
142
  end
@@ -1,17 +1,16 @@
1
1
  module SetsUUID
2
+ VERSION = "1.0.0"
3
+
2
4
  module ClassMethods
3
5
 
4
6
  # Call it on ActiveRecord class definition body:
5
7
  #
6
8
  # sets_uuid :before_create, :attribute_name => :uuid_format.
7
9
  #
8
- # uuid_format is one of the formats available from uuid gem:
9
- # :compact, :urn, :default.
10
- #
11
- # Inspect UUID::FORMATS for the complete list.
10
+ # uuid_format is one of :compact, :default.
12
11
  #
13
12
  def sets_uuid(callback_name, attributes_and_formats_hash)
14
- require 'uuid'
13
+ require 'simple_uuid'
15
14
 
16
15
  raise ArgumentError, "attributes_and_formats_hash does not act as a Hash!" unless attributes_and_formats_hash.respond_to?(:each)
17
16
 
@@ -19,7 +18,13 @@ module SetsUUID
19
18
 
20
19
  meth = "__generate_uuid_for_#{ attribute }".intern
21
20
 
22
- define_method(meth) { write_attribute(attribute, UUID.new.generate(format)) }
21
+ if format == :compact
22
+ implementation = proc { write_attribute(attribute, SimpleUUID::UUID.new.to_guid.gsub(/-/, "")) }
23
+ else
24
+ implementation = proc { write_attribute(attribute, SimpleUUID::UUID.new.to_guid) }
25
+ end
26
+
27
+ include(Module.new { define_method(meth, &implementation) })
23
28
 
24
29
  send(callback_name, meth)
25
30
  end
@@ -1,60 +1,42 @@
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
1
  Gem::Specification.new do |s|
7
- s.name = %q{sets_uuid}
8
- s.version = "0.1.1"
9
-
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
3
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Emmanuel Oga"]
12
- s.date = %q{2009-12-06}
13
- s.description = %q{UUID management for models}
14
- s.email = %q{EmmanuelOga@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/sets_uuid.rb",
27
- "sets_uuid.gemspec",
28
- "spec/sets_uuid_spec.rb",
29
- "spec/spec_helper.rb"
30
- ]
31
- s.homepage = %q{http://github.com/EmmanuelOga/sets_uuid}
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ s.name = 'sets_uuid'
7
+ s.version = '1.0.0'
8
+ s.date = '2010-07-27'
9
+ s.rubyforge_project = 'sets_uuid'
10
+
11
+ s.summary = %q{UUID management for models}
12
+ s.description = %q{Adds declarative uuid attribute initialization to models}
13
+
14
+ s.authors = ["Emmanuel Oga"]
15
+ s.email = 'EmmanuelOga@gmail.com'
16
+ s.homepage = 'http://github.com/emmanueloga'
17
+
18
+ s.require_paths = %w[lib]
19
+
32
20
  s.rdoc_options = ["--charset=UTF-8"]
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.5}
35
- s.summary = %q{Adds declarative uuid attribute initialization to models}
36
- s.test_files = [
37
- "spec/spec_helper.rb",
38
- "spec/sets_uuid_spec.rb"
21
+ s.extra_rdoc_files = %w[README.rdoc LICENSE]
22
+
23
+ s.add_dependency('simple_uuid', [">= 0.1.1"])
24
+ s.add_dependency('activerecord', [">= 2.0.0"])
25
+
26
+ s.add_development_dependency('rspec', [">= 1.1.0", "< 2.0.0"])
27
+
28
+ # = MANIFEST =
29
+ s.files = %w[
30
+ CHANGELOG
31
+ LICENSE
32
+ README.rdoc
33
+ Rakefile
34
+ lib/sets_uuid.rb
35
+ sets_uuid.gemspec
36
+ spec/sets_uuid_spec.rb
37
+ spec/spec_helper.rb
39
38
  ]
39
+ # = MANIFEST =
40
40
 
41
- if s.respond_to? :specification_version then
42
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
- s.specification_version = 3
44
-
45
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<rspec>, [">= 0"])
47
- s.add_runtime_dependency(%q<uuid>, [">= 0"])
48
- s.add_runtime_dependency(%q<activerecord>, [">= 0"])
49
- else
50
- s.add_dependency(%q<rspec>, [">= 0"])
51
- s.add_dependency(%q<uuid>, [">= 0"])
52
- s.add_dependency(%q<activerecord>, [">= 0"])
53
- end
54
- else
55
- s.add_dependency(%q<rspec>, [">= 0"])
56
- s.add_dependency(%q<uuid>, [">= 0"])
57
- s.add_dependency(%q<activerecord>, [">= 0"])
58
- end
41
+ s.test_files = s.files.select { |path| path =~ /^spec\// }
59
42
  end
60
-
@@ -1,38 +1,46 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  class Thing < ActiveRecord::Base
4
- sets_uuid :before_validation, :a => :compact
5
- sets_uuid :before_create, :b => :default
4
+ sets_uuid :before_validation, :compact => :compact
5
+ sets_uuid :before_create, :default => :default
6
6
  end
7
7
 
8
8
  describe "SetsUuid" do
9
- it "should be able to create new things" do
10
- lambda { Thing.create! :a => "1", :b => "2", :c => "3" }.should_not raise_error
9
+ it "does not interfere with things creation" do
10
+ expect { Thing.create!(:some_field => "42") }.to_not raise_error
11
11
  end
12
12
 
13
- it "should be able to set the UUID before validation" do
14
- a = Thing.new
15
- a.a.should be_blank
16
- a.b.should be_blank
17
- a.c.should be_blank
13
+ it "can create compact and default uuids" do
14
+ thing = Thing.create
15
+ thing.compact.should_not =~ /-/
16
+ thing.default.should =~ /-/
17
+ end
18
+
19
+ it "sets the UUID before validation" do
20
+ thing = Thing.new
18
21
 
19
- a.valid?
22
+ thing.compact.should be_blank
23
+ thing.default.should be_blank
24
+ thing.some_field.should be_blank
20
25
 
21
- a.a.should_not be_blank
22
- a.b.should be_blank
23
- a.c.should be_blank
26
+ thing.valid?
27
+
28
+ thing.compact.should_not be_blank
29
+ thing.default.should be_blank
30
+ thing.some_field.should be_blank
24
31
  end
25
32
 
26
- it "should be able to set the UUID before creation" do
27
- a = Thing.new
28
- a.a.should be_blank
29
- a.b.should be_blank
30
- a.c.should be_blank
33
+ it "sets the UUID before creation" do
34
+ thing = Thing.new
35
+
36
+ thing.compact.should be_blank
37
+ thing.default.should be_blank
38
+ thing.some_field.should be_blank
31
39
 
32
- a.save!
40
+ thing.save!
33
41
 
34
- a.a.should_not be_blank
35
- a.b.should_not be_blank
36
- a.c.should be_blank
42
+ thing.compact.should_not be_blank
43
+ thing.default.should_not be_blank
44
+ thing.some_field.should be_blank
37
45
  end
38
46
  end
@@ -1,21 +1,18 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
-
4
- require 'spec'
5
- require 'spec/autorun'
6
- require 'logger'
7
1
  require 'rubygems'
8
2
  require 'activerecord'
3
+ require 'spec/autorun'
9
4
 
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
6
  require 'sets_uuid'
11
7
 
12
8
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
13
9
 
10
+ # require 'logger'
14
11
  # ActiveRecord::Base.logger = Logger.new(STDOUT)
15
12
 
16
13
  ActiveRecord::Schema.define do
17
14
  create_table "things" do |t|
18
- t.string :a, :b, :c
15
+ t.string :compact, :default, :some_field
19
16
  end
20
17
  end
21
18
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sets_uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Emmanuel Oga
@@ -9,61 +15,85 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-06 00:00:00 -03:00
18
+ date: 2010-07-27 00:00:00 -03:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
- name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ name: simple_uuid
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: uuid
29
+ hash: 25
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 1
34
+ version: 0.1.1
27
35
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activerecord
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: activerecord
45
+ hash: 15
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 0
50
+ version: 2.0.0
37
51
  type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
40
58
  requirements:
41
59
  - - ">="
42
60
  - !ruby/object:Gem::Version
43
- version: "0"
44
- version:
45
- description: UUID management for models
61
+ hash: 19
62
+ segments:
63
+ - 1
64
+ - 1
65
+ - 0
66
+ version: 1.1.0
67
+ - - <
68
+ - !ruby/object:Gem::Version
69
+ hash: 15
70
+ segments:
71
+ - 2
72
+ - 0
73
+ - 0
74
+ version: 2.0.0
75
+ type: :development
76
+ version_requirements: *id003
77
+ description: Adds declarative uuid attribute initialization to models
46
78
  email: EmmanuelOga@gmail.com
47
79
  executables: []
48
80
 
49
81
  extensions: []
50
82
 
51
83
  extra_rdoc_files:
52
- - LICENSE
53
84
  - README.rdoc
85
+ - LICENSE
54
86
  files:
55
- - .document
56
- - .gitignore
87
+ - CHANGELOG
57
88
  - LICENSE
58
89
  - README.rdoc
59
90
  - Rakefile
60
- - VERSION
61
91
  - lib/sets_uuid.rb
62
92
  - sets_uuid.gemspec
63
93
  - spec/sets_uuid_spec.rb
64
94
  - spec/spec_helper.rb
65
95
  has_rdoc: true
66
- homepage: http://github.com/EmmanuelOga/sets_uuid
96
+ homepage: http://github.com/emmanueloga
67
97
  licenses: []
68
98
 
69
99
  post_install_message:
@@ -72,24 +102,30 @@ rdoc_options:
72
102
  require_paths:
73
103
  - lib
74
104
  required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
75
106
  requirements:
76
107
  - - ">="
77
108
  - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
78
112
  version: "0"
79
- version:
80
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
81
115
  requirements:
82
116
  - - ">="
83
117
  - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
84
121
  version: "0"
85
- version:
86
122
  requirements: []
87
123
 
88
- rubyforge_project:
89
- rubygems_version: 1.3.5
124
+ rubyforge_project: sets_uuid
125
+ rubygems_version: 1.3.7
90
126
  signing_key:
91
- specification_version: 3
92
- summary: Adds declarative uuid attribute initialization to models
127
+ specification_version: 2
128
+ summary: UUID management for models
93
129
  test_files:
94
- - spec/spec_helper.rb
95
130
  - spec/sets_uuid_spec.rb
131
+ - spec/spec_helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1