acts_as_fu 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acts-as-fu.rb +1 -0
- data/lib/acts_as_fu/constants.rb +2 -0
- data/lib/acts_as_fu/helper.rb +64 -0
- data/lib/acts_as_fu.rb +7 -0
- metadata +66 -0
data/lib/acts-as-fu.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/acts_as_fu.rb'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module ActsAsFu
|
2
|
+
class << self
|
3
|
+
attr_reader :log
|
4
|
+
|
5
|
+
def connect!(config={})
|
6
|
+
@log = ""
|
7
|
+
ActiveRecord::Base.logger = Logger.new(StringIO.new(log))
|
8
|
+
ActiveRecord::Base.establish_connection(config)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def build_model(name, options={}, &block)
|
13
|
+
connect!
|
14
|
+
|
15
|
+
super_class = options[:superclass] || begin
|
16
|
+
ActiveRecord::Base.connection.create_table(name, :force => true) { }
|
17
|
+
ActiveRecord::Base
|
18
|
+
end
|
19
|
+
|
20
|
+
set_class!(name, super_class, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def set_class!(name, super_class, &block)
|
26
|
+
klass_name = name.to_s.classify
|
27
|
+
Object.send(:remove_const, klass_name) rescue nil
|
28
|
+
|
29
|
+
klass = Class.new(super_class)
|
30
|
+
Object.const_set(klass_name, klass)
|
31
|
+
|
32
|
+
model_eval(klass, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def connect!
|
36
|
+
begin
|
37
|
+
# This blows up if there's no connection
|
38
|
+
ActiveRecord::Base.connection
|
39
|
+
rescue
|
40
|
+
ActsAsFu.connect!({
|
41
|
+
:adapter => "sqlite3",
|
42
|
+
:database => ":memory:"
|
43
|
+
})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def model_eval(klass, &block)
|
48
|
+
class << klass
|
49
|
+
def method_missing_with_columns(sym, *args, &block)
|
50
|
+
ActiveRecord::Base.connection.change_table(name.tableize) do |t|
|
51
|
+
t.send(sym, *args)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
alias_method_chain :method_missing, :columns
|
56
|
+
end
|
57
|
+
|
58
|
+
klass.class_eval(&block) if block_given?
|
59
|
+
|
60
|
+
class << klass
|
61
|
+
alias_method :method_missing, :method_missing_without_columns
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/acts_as_fu.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_fu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pat Nakajima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-26 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: patnakajima@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/acts_as_fu
|
35
|
+
- lib/acts-as-fu.rb
|
36
|
+
- lib/acts_as_fu/constants.rb
|
37
|
+
- lib/acts_as_fu/helper.rb
|
38
|
+
- lib/acts_as_fu.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage:
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.3.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: Generate ActiveRecord models on the fly for your tests
|
65
|
+
test_files: []
|
66
|
+
|