activerecord-tableless 0.1.0

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 (6) hide show
  1. data/CHANGELOG +4 -0
  2. data/README +6 -0
  3. data/Rakefile +14 -0
  4. data/init.rb +4 -0
  5. data/lib/tableless.rb +74 -0
  6. metadata +67 -0
@@ -0,0 +1,4 @@
1
+ ActiveRecord::Tableless CHANGELOG
2
+ ---------------------------------
3
+
4
+ 2008-05-01 - Initial code, rough around the edges.
data/README ADDED
@@ -0,0 +1,6 @@
1
+ ActiveRecord Tableless Models
2
+ -----------------------------
3
+
4
+ A single implementation of the ActiveRecord Tableless Model pattern for any
5
+ Rails project or other Ruby project that uses ActiveRecord.
6
+
@@ -0,0 +1,14 @@
1
+ require 'rake/rdoctask'
2
+
3
+ task :default do
4
+ puts
5
+ puts IO.read( File.dirname(__FILE__) + '/README' )
6
+ puts
7
+ end
8
+
9
+ Rake::RDocTask.new do |rd|
10
+ rd.main = 'README'
11
+ rd.rdoc_files.include( 'README', 'lib/*.rb', 'lib/**/*.rb' )
12
+ rd.rdoc_dir = 'rdoc'
13
+ rd.title = 'ActiveRecord Tableless Models'
14
+ end
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ # For use by Railed and de-Railed applications alike
2
+
3
+ require 'activerecord'
4
+ require File.dirname(__FILE__) + '/lib/tableless'
@@ -0,0 +1,74 @@
1
+ # See #ActiveRecord::Tableless
2
+
3
+ module ActiveRecord
4
+
5
+ # = ActiveRecord::Tableless
6
+ #
7
+ # Allow classes to behave like ActiveRecord models, but without an associated
8
+ # database table. A great way to capitalize on validations. Based on the
9
+ # original post at http://www.railsweenie.com/forums/2/topics/724 (which seems
10
+ # to have disappeared from the face of the earth).
11
+ #
12
+ # = Example usage
13
+ #
14
+ # class ContactMessage < ActiveRecord::Base
15
+ #
16
+ # has_no_table
17
+ #
18
+ # column :name, :string
19
+ # column :email, :string
20
+ # column :message, :string
21
+ #
22
+ # end
23
+ #
24
+ # msg = ContactMessage.new( params[:msg] )
25
+ # if msg.valid?
26
+ # ContactMessageSender.deliver_message( msg )
27
+ # redirect_to :action => :sent
28
+ # end
29
+ #
30
+ module Tableless
31
+
32
+ def self.included( base ) #:nodoc:
33
+ base.send( :extend, ClassMethods )
34
+ end
35
+
36
+ module ClassMethods #:nodoc:
37
+
38
+ # A model that needs to be tableless will call this method to indicate
39
+ # it.
40
+ def has_no_table
41
+ # keep our options handy
42
+ write_inheritable_attribute(
43
+ :tableless_options,
44
+ :columns => []
45
+ )
46
+ class_inheritable_reader :tableless_options
47
+
48
+ # extend
49
+ extend ActiveRecord::Tableless::SingletonMethods
50
+
51
+ # setup columns
52
+ end
53
+
54
+ end
55
+
56
+ module SingletonMethods
57
+
58
+ # Return the list of columns registered for the model. Used internally by
59
+ # ActiveRecord
60
+ def columns
61
+ tableless_options[:columns]
62
+ end
63
+
64
+ # Register a new column.
65
+ def column(name, sql_type = nil, default = nil, null = true)
66
+ tableless_options[:columns] << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
73
+
74
+ ActiveRecord::Base.send( :include, ActiveRecord::Tableless )
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-tableless
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenneth Kalmer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-01 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: ActiveRecord Tableless Models provides a simple mixin for creating models that are not bound to the database. This approach is mostly useful for capitalizing on the features ActiveRecord::Validation
25
+ email: kenneth.kalmer@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - CHANGELOG
33
+ files:
34
+ - init.rb
35
+ - lib/tableless.rb
36
+ - Rakefile
37
+ - README
38
+ - CHANGELOG
39
+ has_rdoc: true
40
+ homepage: http://www.opensourcery.co.za/activerecordtableless/
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --main
44
+ - README
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project: tablelessmodels
62
+ rubygems_version: 1.0.1
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: A library for implementing tableless ActiveRecord models
66
+ test_files: []
67
+