arbs 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.
data/README ADDED
@@ -0,0 +1,19 @@
1
+ = arbs
2
+
3
+ arbs is a duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality.
4
+
5
+ by Jay[http://blog.jayfields.com] Fields[http://blog.jayfields.com]
6
+
7
+ == Download and Installation
8
+
9
+ You can download arbs from here[http://rubyforge.org/projects/arbs] or install it with the following command.
10
+
11
+ $ gem install arbs
12
+
13
+ == License
14
+
15
+ You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt).
16
+
17
+ == Contributors
18
+
19
+ George Malamidis
@@ -0,0 +1,19 @@
1
+ module ActiveRecord
2
+ class Base
3
+ stub_class_methods :belongs_to, :has_many, :before_save, :validates_presence_of, :validates_uniqueness_of, :validates_confirmation_of, :serialize
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |key, value|
7
+ self.send "#{key}=".to_sym, value
8
+ end
9
+ end
10
+
11
+ def read_attribute(method_name)
12
+ instance_variable_get "@#{method_name}"
13
+ end
14
+
15
+ def write_attribute(method_name, value)
16
+ instance_variable_set "@#{method_name}", value
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ class Schema
3
+ stub_instance_methods :add_index, :add_foreign_key
4
+
5
+ def self.define(hash, &block)
6
+ self.new.instance_eval(&block)
7
+ end
8
+
9
+ def create_table(name, options)
10
+ yield BehaviorAppender.new(name.singularize.camelize.constantize) unless name == "sessions" || !block_given?
11
+ end
12
+ end
13
+ end
data/lib/arbs.rb ADDED
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/class_extensions'
2
+ require File.dirname(__FILE__) + '/arbs_generator'
3
+ require File.dirname(__FILE__) + '/behavior_appender'
4
+ require File.dirname(__FILE__) + '/active_record/base'
5
+ require File.dirname(__FILE__) + '/active_record/schema'
@@ -0,0 +1,5 @@
1
+ class ArbsGenerator
2
+ def self.run(schema_path)
3
+ load schema_path
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ class BehaviorAppender
2
+ attr_accessor :klass
3
+ def initialize(klass)
4
+ self.klass = klass
5
+ end
6
+
7
+ def column(name, type, options={})
8
+ klass.class_eval do
9
+ attr_reader name.to_sym unless instance_methods.include?(name.to_s)
10
+ attr_writer name.to_sym unless instance_methods.include?("#{name}=")
11
+ if type.to_sym == :boolean
12
+ define_method "#{name}?".to_sym do
13
+ self.send name
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ module ClassExtensions
2
+ end
3
+
4
+ class Class
5
+ include ClassExtensions
6
+
7
+ def stub_class_methods(*args)
8
+ class<<self; self; end.class_eval do
9
+ args.each do |method_name|
10
+ define_method method_name do |*args|
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ def stub_instance_methods(*args)
17
+ class_eval do
18
+ args.each do |method_name|
19
+ define_method method_name do |*args|
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+
data/rakefile.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/contrib/sshpublisher'
5
+
6
+ task :default do
7
+ require File.dirname(__FILE__) + '/test/all_tests.rb'
8
+ end
9
+
10
+ desc 'Generate RDoc'
11
+ Rake::RDocTask.new do |task|
12
+ task.main = 'README'
13
+ task.title = 'arbs'
14
+ task.rdoc_dir = 'doc'
15
+ task.options << "--line-numbers" << "--inline-source"
16
+ task.rdoc_files.include('README', 'lib/**/*.rb')
17
+ end
18
+
19
+ desc "Upload RDoc to RubyForge"
20
+ task :publish_rdoc => [:rdoc] do
21
+ Rake::SshDirPublisher.new("jaycfields@rubyforge.org", "/var/www/gforge-projects/arbs", "doc").upload
22
+ end
23
+
24
+ Gem::manage_gems
25
+
26
+ specification = Gem::Specification.new do |s|
27
+ s.name = "arbs"
28
+ s.summary = "A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality."
29
+ s.version = "0.0.1"
30
+ s.author = 'Jay Fields'
31
+ s.description = "A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality."
32
+ s.homepage = 'http://arbs.rubyforge.org'
33
+ s.rubyforge_project = 'arbs'
34
+
35
+ s.has_rdoc = true
36
+ s.extra_rdoc_files = ['README']
37
+ s.rdoc_options << '--title' << 'arbs' << '--main' << 'README' << '--line-numbers'
38
+
39
+ s.autorequire = 'arbs'
40
+ s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*$', 'rakefile.rb'].to_a
41
+ s.test_file = "test/all_tests.rb"
42
+ end
43
+
44
+ Rake::GemPackageTask.new(specification) do |package|
45
+ package.need_zip = false
46
+ package.need_tar = false
47
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ unit_tests do
4
+
5
+ test "stub belongs_to" do
6
+ assert_equal true, ActiveRecord::Base.methods.include?("belongs_to")
7
+ end
8
+
9
+ test "stub has_many" do
10
+ assert_equal true, ActiveRecord::Base.methods.include?("has_many")
11
+ end
12
+
13
+ test "stub before_save" do
14
+ assert_equal true, ActiveRecord::Base.methods.include?("before_save")
15
+ end
16
+
17
+ test "stub validates_presence_of" do
18
+ assert_equal true, ActiveRecord::Base.methods.include?("validates_presence_of")
19
+ end
20
+
21
+ test "stub validates_uniqueness_of" do
22
+ assert_equal true, ActiveRecord::Base.methods.include?("validates_uniqueness_of")
23
+ end
24
+
25
+ test "stub validates_confirmation_of" do
26
+ assert_equal true, ActiveRecord::Base.methods.include?("validates_confirmation_of")
27
+ end
28
+
29
+ test "stub serialize" do
30
+ assert_equal true, ActiveRecord::Base.methods.include?("serialize")
31
+ end
32
+
33
+ test "initialize via options" do
34
+ klass = Class.new(ActiveRecord::Base) do
35
+ attr_accessor :foo, :bar
36
+ end
37
+ instance = klass.new(:foo=>"foo", :bar=>"bar")
38
+ assert_equal ["foo", "bar"], [instance.foo, instance.bar]
39
+ end
40
+
41
+ test "read attribute returns the instance_variable" do
42
+ klass = Class.new(ActiveRecord::Base) do
43
+ attr_accessor :foo
44
+ end
45
+ assert_equal "foo", klass.new(:foo=>"foo").read_attribute(:foo)
46
+ end
47
+
48
+ test "write attribute sets the instance_variable" do
49
+ klass = Class.new(ActiveRecord::Base) do
50
+ attr_accessor :foo
51
+ end
52
+ instance = klass.new(:foo=>"foo")
53
+ instance.write_attribute(:foo, 1)
54
+ assert_equal 1, instance.foo
55
+ end
56
+
57
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ unit_tests do
4
+ test "stub add index" do
5
+ assert_equal true, ActiveRecord::Schema.instance_methods.include?("add_index")
6
+ end
7
+
8
+ test "stub foreign key" do
9
+ assert_equal true, ActiveRecord::Schema.instance_methods.include?("add_foreign_key")
10
+ end
11
+
12
+ Table = 1
13
+ test "create table" do
14
+ schema = ActiveRecord::Schema.new
15
+ assert_equal 1, schema.create_table("tables", nil) { |val| val.klass }
16
+ end
17
+
18
+ end
data/test/all_tests.rb ADDED
@@ -0,0 +1 @@
1
+ Dir['**/*_test.rb'].each { |test_case| require test_case }
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ unit_tests do
4
+
5
+ test "column creates readers for each column" do
6
+ klass = Class.new
7
+ BehaviorAppender.new(klass).column("foo", "string")
8
+ assert_equal true, klass.instance_methods.include?("foo")
9
+ end
10
+
11
+ test "column creates writers for each column" do
12
+ klass = Class.new
13
+ BehaviorAppender.new(klass).column("foo", "string")
14
+ assert_equal true, klass.instance_methods.include?("foo=")
15
+ end
16
+
17
+ test "column doesnt create readers if methods already exist" do
18
+ klass = Class.new do
19
+ def foo
20
+ "foo"
21
+ end
22
+ end
23
+ BehaviorAppender.new(klass).column("foo", "string")
24
+ instance = klass.new
25
+ assert_equal "foo", instance.foo
26
+ end
27
+
28
+ test "column doesnt create writer if methods already exist" do
29
+ klass = Class.new do
30
+ def foo=(value)
31
+ @foo = "foo"
32
+ end
33
+ end
34
+ BehaviorAppender.new(klass).column("foo", "string")
35
+ instance = klass.new
36
+ instance.foo = 3
37
+ assert_equal "foo", instance.foo
38
+ end
39
+
40
+ test "boolean method is defined if the type is boolean" do
41
+ klass = Class.new
42
+ BehaviorAppender.new(klass).column("foo", "boolean")
43
+ assert_equal true, klass.instance_methods.include?("foo?")
44
+ end
45
+
46
+ end
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'dust'
4
+ require 'active_support'
5
+ require File.dirname(__FILE__) + '/../lib/arbs'
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: arbs
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-10-27 00:00:00 +01:00
8
+ summary: A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality.
9
+ require_paths:
10
+ - lib
11
+ email:
12
+ homepage: http://arbs.rubyforge.org
13
+ rubyforge_project: arbs
14
+ description: A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality.
15
+ autorequire: arbs
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Jay Fields
31
+ files:
32
+ - lib/active_record/base.rb
33
+ - lib/active_record/schema.rb
34
+ - lib/arbs.rb
35
+ - lib/arbs_generator.rb
36
+ - lib/behavior_appender.rb
37
+ - lib/class_extensions.rb
38
+ - test/active_record/base_test.rb
39
+ - test/active_record/schema_test.rb
40
+ - test/all_tests.rb
41
+ - test/behavior_appender_test.rb
42
+ - test/test_helper.rb
43
+ - rakefile.rb
44
+ - README
45
+ test_files:
46
+ - test/all_tests.rb
47
+ rdoc_options:
48
+ - --title
49
+ - arbs
50
+ - --main
51
+ - README
52
+ - --line-numbers
53
+ extra_rdoc_files:
54
+ - README
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ requirements: []
60
+
61
+ dependencies: []
62
+