has-versions 0.0.0 → 0.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.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gem.email = "onland@alias.nl"
11
11
  gem.homepage = "http://github.com/onland/has-versions"
12
12
  gem.authors = ["Sander Onland"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
13
+ # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -0,0 +1,51 @@
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{has-versions}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sander Onland"]
12
+ s.date = %q{2010-08-05}
13
+ s.description = %q{}
14
+ s.email = %q{onland@alias.nl}
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
+ "has-versions.gemspec",
27
+ "lib/has-versions.rb",
28
+ "test/helper.rb",
29
+ "test/test_has-versions.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/onland/has-versions}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{Adds versioning to existing active-record models}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_has-versions.rb"
39
+ ]
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::VERSION) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ end
51
+
data/lib/has-versions.rb CHANGED
@@ -36,12 +36,13 @@ module VersionIncludes
36
36
  scope :with_version, lambda {|version| self.where("version <= '#{version}'") }
37
37
 
38
38
  before_create 'before_create_initialization'
39
+ after_create 'after_create_initialization'
39
40
 
40
41
  end
41
42
  end
42
43
 
43
44
  def histories
44
- self.class.where(:uid=>uid).where(:state=>'history').all
45
+ self.class.where(:uid=>uid).where(:state=>'history').order('version DESC').all
45
46
  end
46
47
  def draft
47
48
  self.class.where(:uid=>uid).where(:state=>'draft').all.first
@@ -56,6 +57,13 @@ module VersionIncludes
56
57
  self.state = 'draft'
57
58
  self.version = nil
58
59
  end
60
+
61
+ def after_create_initialization
62
+ if self.uid.nil?
63
+ self.uid = id
64
+ self.save
65
+ end
66
+ end
59
67
 
60
68
  def draft!
61
69
  self.state = 'draft'
@@ -82,7 +90,7 @@ module VersionIncludes
82
90
  end
83
91
 
84
92
  def restore!
85
- if history?
93
+ if history? || publication?
86
94
  draft.destroy if draft
87
95
  create_draft!
88
96
  end
@@ -118,6 +126,6 @@ module VersionIncludes
118
126
  end
119
127
 
120
128
  def commitable?
121
- draft? && (self.created_at!=self.updated_at)
129
+ draft? && (self.created_at.to_i!=self.updated_at.to_i)
122
130
  end
123
131
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has-versions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sander Onland
@@ -15,23 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-01 00:00:00 +02:00
18
+ date: 2010-08-05 00:00:00 +02:00
19
19
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: thoughtbot-shoulda
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- type: :development
34
- version_requirements: *id001
20
+ dependencies: []
21
+
35
22
  description: ""
36
23
  email: onland@alias.nl
37
24
  executables: []
@@ -48,6 +35,7 @@ files:
48
35
  - README.rdoc
49
36
  - Rakefile
50
37
  - VERSION
38
+ - has-versions.gemspec
51
39
  - lib/has-versions.rb
52
40
  - test/helper.rb
53
41
  - test/test_has-versions.rb