paresseux 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require 'mongoid'
3
+
4
+ module Mongoid
5
+ module Paresseux
6
+ extend ::ActiveSupport::Concern
7
+
8
+ included do
9
+ field :paresseux_version, type: Integer, default: self::VERSION
10
+ after_initialize :paresseux_migrate
11
+ before_save :set_paresseux_version
12
+ end
13
+
14
+ private
15
+
16
+ def paresseux_migrate
17
+ if paresseux_version < current_paresseux_version
18
+ "#{self.class}Paresseux".constantize.new(self, current_paresseux_version).migrate!
19
+ end
20
+ end
21
+
22
+ def set_paresseux_version
23
+ self.paresseux_version = current_paresseux_version
24
+ end
25
+
26
+ def current_paresseux_version
27
+ self.class::VERSION
28
+ end
29
+
30
+ end # Paresseux
31
+ end # Mongoid
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ module Paresseux
3
+ class Migration
4
+ attr_reader :model, :version, :current_version
5
+
6
+ def initialize(model, version)
7
+ @model, @version, @current_version = model, version, model.paresseux_version
8
+ end
9
+
10
+ def migrate
11
+ (current_version...version).each do |index|
12
+ send("migration_#{index}_to_#{index + 1}")
13
+ end
14
+ end
15
+
16
+ def migrate!
17
+ migrate
18
+ model.save
19
+ end
20
+ end # Migration
21
+ end # Paresseux
@@ -0,0 +1,3 @@
1
+ module Paresseux
2
+ VERSION = "0.0.1"
3
+ end
data/lib/paresseux.rb ADDED
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+ require 'mongoid/paresseux'
3
+ require 'paresseux/migration'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paresseux
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - chatgris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &21025140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.8'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *21025140
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &21024640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *21024640
36
+ - !ruby/object:Gem::Dependency
37
+ name: mongoid
38
+ requirement: &21024180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.4'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *21024180
47
+ - !ruby/object:Gem::Dependency
48
+ name: bson_ext
49
+ requirement: &21023720 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *21023720
58
+ description: Lazy migration tool for active model aware model.
59
+ email: jboyer@af83.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - lib/mongoid/paresseux.rb
65
+ - lib/paresseux.rb
66
+ - lib/paresseux/migration.rb
67
+ - lib/paresseux/version.rb
68
+ homepage: https://github.com/chatgris/paresseux
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.10
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Lazy migration tool for active model aware model.
92
+ test_files: []