is_sequenced 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/is_sequenced.rb +38 -0
  2. metadata +67 -0
@@ -0,0 +1,38 @@
1
+ module IsSequenced
2
+
3
+ def is_sequenced parent_class_name
4
+ @is_sequenced_parent_name = parent_class_name
5
+ include ChildInstanceMethods
6
+
7
+ parent_class = parent_class_name.to_s.classify.constantize
8
+ class_name = name.underscore
9
+
10
+ parent_class.class_eval do
11
+ define_method "increment_#{ class_name }_sequence!" do
12
+ value = send "#{ class_name }_sequence"
13
+ send "#{ class_name }_sequence=", value + 1
14
+ save
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ module ChildInstanceMethods
21
+
22
+ def is_sequenced_parent_name
23
+ self.class.instance_variable_get '@is_sequenced_parent_name'
24
+ end
25
+
26
+ def is_sequenced_parent
27
+ send is_sequenced_parent_name
28
+ end
29
+
30
+ def set_sequence!
31
+ class_name = self.class.name.underscore
32
+ self.sequence = is_sequenced_parent.send "#{class_name}_sequence"
33
+ is_sequenced_parent.send "increment_#{class_name}_sequence!" if save
34
+ end
35
+
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_sequenced
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Dev Fu!
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-29 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Simplify creation of a sequence column in a class, scoped to another class.
23
+ email: info@devfu.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/is_sequenced.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/devfu/is_sequenced
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.7
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Add a sequenced attribute to a class.
66
+ test_files: []
67
+