nakajima-acts_as_fu 0.0.1 → 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 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 CHANGED
@@ -1,21 +1,7 @@
1
1
  $LOAD_PATH << File.dirname(__FILE__) + '/acts_as_fu'
2
2
 
3
- %w(rubygems activerecord constants).each { |lib| require lib }
4
-
5
3
  module ActsAsFu
6
- def build_model(name, &block)
7
- ActiveRecord::Base.establish_connection({
8
- :adapter => "sqlite3",
9
- :database => ":memory:"
10
- })
11
-
12
- ActiveRecord::Base.connection.create_table name, :force => true do |table|
13
- table.instance_eval(&block)
14
- end
15
-
16
- klass_name = name.to_s.classify
17
-
18
- Object.send(:remove_const, klass_name) rescue nil
19
- Object.const_set(klass_name, Class.new(ActiveRecord::Base))
20
- end
4
+ VERSION = '0.0.2'
21
5
  end
6
+
7
+ %w(rubygems activerecord constants helper).each { |lib| require lib }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nakajima-acts_as_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Nakajima
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-23 00:00:00 -07:00
12
+ date: 2008-10-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,9 @@ extra_rdoc_files: []
31
31
 
32
32
  files:
33
33
  - lib/acts_as_fu
34
+ - lib/acts-as-fu.rb
34
35
  - lib/acts_as_fu/constants.rb
36
+ - lib/acts_as_fu/helper.rb
35
37
  - lib/acts_as_fu.rb
36
38
  has_rdoc: true
37
39
  homepage: