nakajima-acts_as_fu 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/acts_as_fu/base.rb +14 -15
  2. metadata +1 -1
@@ -21,27 +21,25 @@ module ActsAsFu
21
21
  def build_model(name, options={}, &block)
22
22
  connect! unless connected?
23
23
 
24
- super_class = options[:superclass] || begin
25
- ActsAsFu::Connection.connection.create_table(name, :force => true) { }
26
- ActsAsFu::Connection
27
- end
28
-
29
- set_class!(name, super_class, &block)
30
- end
31
-
32
- private
33
-
34
- def set_class!(name, super_class, &block)
35
- klass_name = name.to_s.classify
36
- Object.send(:remove_const, klass_name) rescue nil
24
+ klass_name = name.to_s.classify
25
+ super_class = options[:superclass] || ActsAsFu::Connection
26
+ contained = options[:contained] || Object
37
27
 
28
+ contained.send(:remove_const, klass_name) rescue nil
38
29
  klass = Class.new(super_class)
39
- Object.const_set(klass_name, klass)
30
+ contained.const_set(klass_name, klass)
31
+
32
+ # table_name isn't available until after the class is created.
33
+ if super_class == ActsAsFu::Connection
34
+ ActsAsFu::Connection.connection.create_table(klass.table_name, :force => true) { }
35
+ end
40
36
 
41
37
  model_eval(klass, &block)
42
38
  klass
43
39
  end
44
40
 
41
+ private
42
+
45
43
  def connect!
46
44
  ActsAsFu::Connection.connect!({
47
45
  :adapter => "sqlite3",
@@ -57,7 +55,7 @@ module ActsAsFu
57
55
  def model_eval(klass, &block)
58
56
  class << klass
59
57
  def method_missing_with_columns(sym, *args, &block)
60
- ActsAsFu::Connection.connection.change_table(name.tableize) do |t|
58
+ ActsAsFu::Connection.connection.change_table(table_name) do |t|
61
59
  t.send(sym, *args)
62
60
  end
63
61
  end
@@ -71,4 +69,5 @@ module ActsAsFu
71
69
  alias_method :method_missing, :method_missing_without_columns
72
70
  end
73
71
  end
72
+
74
73
  end
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Nakajima