jcnetdev-active_record_without_table 1.0.20070427

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.
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ [27 April 2007]
2
+
3
+ * Correctly cache class instance variables containing column information [Reported by Nils Jonsson]
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 Jonathan Viney
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,29 @@
1
+ = ActiveRecordBaseWithoutTable
2
+
3
+ If you find this plugin useful, please consider a donation to show your support!
4
+
5
+ http://www.paypal.com/cgi-bin/webscr?cmd=_send-money
6
+
7
+ Email address: jonathan.viney@gmail.com
8
+
9
+ == Instructions
10
+
11
+ * For edge Rails r7315 or above use http://svn.viney.net.nz/things/branches/active_record_base_without_table
12
+
13
+ Get the power of ActiveRecord models, including validation, without having a table in the database.
14
+
15
+ class Contact < ActiveRecord::BaseWithoutTable
16
+ column :name, :string
17
+ column :email_address, :string
18
+ column :message, :text
19
+
20
+ validates_presence_of :name, :email_address, :string
21
+ end
22
+
23
+ This model can be used just like a regular model based on a table, except it will never be saved to the database.
24
+
25
+ There is a good blog post available on the plugin:
26
+
27
+ http://www.kangarooit.com/developer_blog/2007/02/email-form-validation-in-ruby-on-rails.php
28
+
29
+ Any bugs, questions, comments please feel free to email me: jonathan.viney@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the active_record_base_without_table plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the active_record_base_without_table plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'ActiveRecordBaseWithoutTable'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,33 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'active_record_without_table'
3
+ s.version = '1.0.20070427'
4
+ s.date = '2007-04-27'
5
+
6
+ s.summary = "Allows creation of ActiveRecord models that work without any database backend"
7
+ s.description = "Get the power of ActiveRecord models, including validation, without having a table in the database."
8
+
9
+ s.authors = ['Jacques Crocker', 'Jonathan Viney']
10
+ s.email = 'railsjedi@gmail.com'
11
+ s.homepage = 'http://github.com/jcnetdev/active_record_without_table'
12
+
13
+ s.has_rdoc = true
14
+ s.rdoc_options = ["--main", "README"]
15
+ #s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
16
+
17
+ s.add_dependency 'activerecord', ['>= 2.0']
18
+
19
+ s.files = ["CHANGELOG",
20
+ "MIT-LICENSE",
21
+ "README",
22
+ "Rakefile",
23
+ "init.rb",
24
+ "rails/init.rb",
25
+ "active_record_without_table.gemspec",
26
+ "lib/active_record",
27
+ "lib/active_record/base_without_table.rb"]
28
+
29
+ s.test_files = ["test/abstract_unit.rb",
30
+ "test/active_record_base_without_table_test.rb",
31
+ "test/database.yml"]
32
+
33
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
@@ -0,0 +1,26 @@
1
+ module ActiveRecord
2
+ class BaseWithoutTable < Base
3
+ self.abstract_class = true
4
+
5
+ def create_or_update
6
+ errors.empty?
7
+ end
8
+
9
+ class << self
10
+ def columns()
11
+ @columns ||= []
12
+ end
13
+
14
+ def column(name, sql_type = nil, default = nil, null = true)
15
+ columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
16
+ reset_column_information
17
+ end
18
+
19
+ # Do not reset @columns
20
+ def reset_column_information
21
+ generated_methods.each { |name| undef_method(name) }
22
+ @column_names = @columns_hash = @content_columns = @dynamic_methods_hash = @read_methods = nil
23
+ end
24
+ end
25
+ end
26
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ # Plugin intialization code here...
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+
3
+ begin
4
+ require File.dirname(__FILE__) + '/../../../../config/boot'
5
+ require 'active_record'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require_gem 'activerecord'
9
+ end
10
+
11
+ require File.dirname(__FILE__) + '/../lib/active_record/base_without_table'
12
+
13
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
14
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
15
+ ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'mysql'])
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/abstract_unit'
2
+
3
+ class Person < ActiveRecord::BaseWithoutTable
4
+ column :name, :string
5
+ column :lucky_number, :integer, 4
6
+
7
+ validates_presence_of :name
8
+ end
9
+
10
+ class ActiveRecordBaseWithoutTableTest < Test::Unit::TestCase
11
+ def test_default_value
12
+ assert_equal 4, Person.new.lucky_number
13
+ end
14
+
15
+ def test_validation
16
+ p = Person.new
17
+
18
+ assert !p.save
19
+ assert p.errors[:name]
20
+
21
+ assert p.update_attributes(:name => 'Name')
22
+ end
23
+
24
+ def test_typecast
25
+ assert_equal 1, Person.new(:lucky_number => "1").lucky_number
26
+ end
27
+
28
+ def test_cached_column_variables_reset_when_column_defined
29
+ cached_variables = %w(column_names columns_hash content_columns dynamic_methods_hash read_methods)
30
+
31
+ Person.column_names
32
+ Person.columns_hash
33
+ Person.content_columns
34
+ Person.column_methods_hash
35
+ Person.read_methods
36
+
37
+ cached_variables.each { |v| assert_not_nil Person.instance_variable_get("@#{v}") }
38
+ Person.column :new_column, :string
39
+ cached_variables.each { |v| assert_nil Person.instance_variable_get("@#{v}") }
40
+ end
41
+ end
data/test/database.yml ADDED
@@ -0,0 +1,6 @@
1
+ mysql:
2
+ :adapter: mysql
3
+ :host: localhost
4
+ :username: rails
5
+ :password:
6
+ :database: rails_plugin_test
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jcnetdev-active_record_without_table
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.20070427
5
+ platform: ruby
6
+ authors:
7
+ - Jacques Crocker
8
+ - Jonathan Viney
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2007-04-27 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activerecord
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "2.0"
24
+ version:
25
+ description: Get the power of ActiveRecord models, including validation, without having a table in the database.
26
+ email: railsjedi@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - CHANGELOG
35
+ - MIT-LICENSE
36
+ - README
37
+ - Rakefile
38
+ - init.rb
39
+ - rails/init.rb
40
+ - active_record_without_table.gemspec
41
+ - lib/active_record
42
+ - lib/active_record/base_without_table.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/jcnetdev/active_record_without_table
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --main
48
+ - README
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Allows creation of ActiveRecord models that work without any database backend
70
+ test_files:
71
+ - test/abstract_unit.rb
72
+ - test/active_record_base_without_table_test.rb
73
+ - test/database.yml