Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code revision, renaming of project

  • Loading branch information...
commit 646708771c197b08bdfab210fcbd6c492d5db585 1 parent 27c703e
Michal Zima authored
View
6 CHANGELOG
@@ -1,4 +1,2 @@
-ActiveRecord::Tableless CHANGELOG
----------------------------------
-
-2008-05-01 - Initial code, rough around the edges.
+0.1.0 - May 1st 2008
+ * Initial code, rough around the edges.
View
13 README
@@ -1,8 +1,8 @@
-ActiveRecord Tableless Models
------------------------------
+ActiveRecord Tableless
+----------------------
-A single implementation of the ActiveRecord Tableless Model pattern for any
-Rails project or other Ruby project that uses ActiveRecord.
+A single implementation of the ActiveRecord Tableless pattern for any Rails
+project or other Ruby project that uses ActiveRecord.
Define a model like this:
@@ -32,4 +32,7 @@ def message
end
end
-
+Credits
+-------
+Michal Zima <xhire@tuxportal.cz>
+Kenneth Kalmer <kenneth.kalmer@gmail.com> (original author)
View
8 Rakefile
@@ -2,13 +2,13 @@ require 'rake/rdoctask'
task :default do
puts
- puts IO.read( File.dirname(__FILE__) + '/README' )
+ puts IO.read(File.join(File.dirname(__FILE__), 'README')
puts
end
Rake::RDocTask.new do |rd|
rd.main = 'README'
- rd.rdoc_files.include( 'README', 'lib/*.rb', 'lib/**/*.rb' )
+ rd.rdoc_files.include('README', 'lib/*.rb', 'lib/**/*.rb')
rd.rdoc_dir = 'rdoc'
- rd.title = 'ActiveRecord Tableless Models'
-end
+ rd.title = 'ActiveRecord Tableless'
+end
View
5 TODO
@@ -1,6 +1,3 @@
-ActiveRecord::Tableless TODO
-----------------------------
-
0.1.x (Make it useful)
* More documentation, better examples
* Tests
@@ -11,4 +8,4 @@ ActiveRecord::Tableless TODO
0.3.x (Transporter series)
* Use tableless models to easily serialize/deserialize data for portability
- (not persistance)
+ (not persistance)
View
20 activerecord-tableless-models.gemspec
@@ -1,20 +0,0 @@
-require 'rubygems'
-require 'rake'
-
-spec = Gem::Specification.new do |spec|
- spec.name = 'activerecord-tableless'
- spec.summary = %q{A library for implementing tableless ActiveRecord models}
- spec.description = %q{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}
- spec.author = "Kenneth Kalmer"
- spec.email = "kenneth.kalmer@gmail.com"
- spec.homepage = "http://www.opensourcery.co.za/activerecordtableless/"
- #spec.files = [ "Rakefile", "README", "CHANGELOG" ]
- #spec.files << Dir["lib/*"]
- spec.files = FileList[ "*.rb", "lib/*.rb", "Rakefile", "README", "CHANGELOG" ]
- spec.version = "0.1.0"
- spec.add_dependency("activerecord")
- spec.has_rdoc = true
- spec.extra_rdoc_files = %w( README CHANGELOG )
- spec.rdoc_options.concat ['--main', 'README']
- spec.rubyforge_project = 'tablelessmodels'
-end
View
16 activerecord-tableless.gemspec
@@ -0,0 +1,16 @@
+require 'rubygems'
+require 'rake'
+
+spec = Gem::Specification.new do |spec|
+ spec.name = 'activerecord-tableless'
+ spec.summary = %q{A library for implementing tableless ActiveRecord models}
+ spec.description = %q{ActiveRecord Tableless 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}
+ spec.author = "Michal Zima"
+ spec.email = "xhire@mujmalysvet.cz"
+ spec.files = FileList[ "*.rb", "lib/*.rb", "Rakefile", "README", "CHANGELOG" ]
+ spec.version = "0.1.0"
+ spec.add_dependency("activerecord")
+ spec.has_rdoc = true
+ spec.extra_rdoc_files = %w( README CHANGELOG )
+ spec.rdoc_options.concat ['--main', 'README']
+end
View
2  init.rb
@@ -1,4 +1,4 @@
# For use by Railed and de-Railed applications alike
require 'activerecord'
-require File.dirname(__FILE__) + '/lib/tableless'
+require File.join(File.dirname(__FILE__), 'lib', 'activerecord-tableless')
View
82 lib/tableless.rb → lib/activerecord-tableless.rb
@@ -1,26 +1,26 @@
# See #ActiveRecord::Tableless
module ActiveRecord
-
+
# = ActiveRecord::Tableless
- #
+ #
# Allow classes to behave like ActiveRecord models, but without an associated
# database table. A great way to capitalize on validations. Based on the
# original post at http://www.railsweenie.com/forums/2/topics/724 (which seems
# to have disappeared from the face of the earth).
- #
+ #
# = Example usage
- #
+ #
# class ContactMessage < ActiveRecord::Base
- #
+ #
# has_no_table
- #
+ #
# column :name, :string
# column :email, :string
# column :message, :string
- #
+ #
# end
- #
+ #
# msg = ContactMessage.new( params[:msg] )
# if msg.valid?
# ContactMessageSender.deliver_message( msg )
@@ -28,13 +28,13 @@ module ActiveRecord
# end
#
module Tableless
-
- def self.included( base ) #:nodoc:
- base.send( :extend, ActsMethods )
+
+ def self.included(base) #:nodoc:
+ base.send :extend, ActsMethods
end
-
+
module ActsMethods #:nodoc:
-
+
# A model that needs to be tableless will call this method to indicate
# it.
def has_no_table
@@ -44,45 +44,45 @@ def has_no_table
:columns => []
)
class_inheritable_reader :tableless_options
-
+
# extend
- extend ActiveRecord::Tableless::SingletonMethods
- extend ActiveRecord::Tableless::ClassMethods
-
+ extend ActiveRecord::Tableless::SingletonMethods
+ extend ActiveRecord::Tableless::ClassMethods
+
# include
include ActiveRecord::Tableless::InstanceMethods
-
+
# setup columns
end
-
+
end
-
+
module SingletonMethods
-
+
# Return the list of columns registered for the model. Used internally by
# ActiveRecord
def columns
tableless_options[:columns]
end
-
+
# Register a new column.
def column(name, sql_type = nil, default = nil, null = true)
tableless_options[:columns] << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
-
- %w(find create destroy).each do |m|
- eval %{
+
+ %w(find create destroy).each do |m|
+ eval %{
def #{m}
logger.warn "Can't #{m} a Tableless object"
false
end
}
end
-
+
end
-
+
module ClassMethods
-
+
def from_query_string(query_string)
unless query_string.blank?
params = query_string.split('&').collect do |chunk|
@@ -92,36 +92,36 @@ def from_query_string(query_string)
value = value.nil? ? nil : CGI.unescape(value)
[ CGI.unescape(key), value ]
end.compact.to_h
-
+
new(params)
else
new
end
end
-
+
end
-
+
module InstanceMethods
-
+
def to_query_string(prefix = nil)
attributes.to_a.collect{|(name,value)| escaped_var_name(name, prefix) + "=" + escape_for_url(value) if value }.compact.join("&")
end
-
- %w(save destroy).each do |m|
- eval %{
+
+ %w(save destroy).each do |m|
+ eval %{
def #{m}
logger.warn "Can't #{m} a Tableless object"
false
end
}
end
-
+
private
-
+
def escaped_var_name(name, prefix = nil)
prefix ? "#{URI.escape(prefix)}[#{URI.escape(name)}]" : URI.escape(name)
end
-
+
def escape_for_url(value)
case value
when true then "1"
@@ -132,10 +132,10 @@ def escape_for_url(value)
rescue
""
end
-
+
end
-
+
end
end
-ActiveRecord::Base.send( :include, ActiveRecord::Tableless )
+ActiveRecord::Base.send :include, ActiveRecord::Tableless
Please sign in to comment.
Something went wrong with that request. Please try again.