active_record_composition 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.
Files changed (2) hide show
  1. data/lib/active_record_composition.rb +41 -0
  2. metadata +61 -0
@@ -0,0 +1,41 @@
1
+ require 'active_record'
2
+
3
+ class String
4
+ def underscore
5
+ self.gsub(/::/, '/').
6
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
7
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
8
+ tr("-", "_").
9
+ downcase
10
+ end
11
+ end
12
+
13
+ module ActiveRecordComposition
14
+
15
+ module ClassMethods
16
+ def active_composite=(active_composite)
17
+ @active_composite = active_composite
18
+ end
19
+
20
+ def active_composite
21
+ @active_composite
22
+ end
23
+
24
+ def method_missing(method, *args, &block)
25
+ @active_composite.send method, *args, &block
26
+ end
27
+
28
+ end
29
+
30
+ def self.included(base)
31
+ base.extend(ClassMethods)
32
+ base.active_composite = Object.const_set("#{base.name}ActiveComposite", Class.new(ActiveRecord::Base) do
33
+ def is_a?(compared)
34
+ return true if (self.class.name.gsub('ActiveComposite', '') == compared.name)
35
+ super.is_a? compared
36
+ end
37
+ end)
38
+ base.active_composite.table_name = "#{base.name}s".underscore
39
+ end
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record_composition
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Beddingfield
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: &10861860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *10861860
25
+ description: ActiveRecord is awesome, inheritance is not always so awesome. This gem
26
+ is for people who want to use ActiveRecord but don't want to be forced to use inheritance
27
+ in their models. Magic stuff happens that keeps the ActiveRecord::Base relationship
28
+ away from your model object graph until runtime but you can still use all the ActiveRecord
29
+ methods on your model as you're accustomed to. Also, you now have an inheritance
30
+ slot freed up - easy peasy :-)
31
+ email: kevin.beddingfield@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/active_record_composition.rb
37
+ homepage: http://github.com/chumpy/ActiveRecordComposition
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.10
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Enables ActiveRecord binding and functionality without using inheritance
61
+ test_files: []