Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support for nested classes

  • Loading branch information...
commit 2cb35a5650542a30a63efeaea1ee9a04154b0b93 1 parent 90f24a9
@flavorjones flavorjones authored
Showing with 14 additions and 15 deletions.
  1. +14 −15 lib/acts_as_fu/base.rb
View
29 lib/acts_as_fu/base.rb
@@ -21,27 +21,25 @@ def self.connect!(config={})
def build_model(name, options={}, &block)
connect! unless connected?
- super_class = options[:superclass] || begin
- ActsAsFu::Connection.connection.create_table(name, :force => true) { }
- ActsAsFu::Connection
- end
-
- set_class!(name, super_class, &block)
- end
-
- private
-
- def set_class!(name, super_class, &block)
- klass_name = name.to_s.classify
- Object.send(:remove_const, klass_name) rescue nil
+ klass_name = name.to_s.classify
+ super_class = options[:superclass] || ActsAsFu::Connection
+ contained = options[:contained] || Object
+ contained.send(:remove_const, klass_name) rescue nil
klass = Class.new(super_class)
- Object.const_set(klass_name, klass)
+ contained.const_set(klass_name, klass)
+
+ # table_name isn't available until after the class is created.
+ if super_class == ActsAsFu::Connection
+ ActsAsFu::Connection.connection.create_table(klass.table_name, :force => true) { }
+ end
model_eval(klass, &block)
klass
end
+ private
+
def connect!
ActsAsFu::Connection.connect!({
:adapter => "sqlite3",
@@ -57,7 +55,7 @@ def connected?
def model_eval(klass, &block)
class << klass
def method_missing_with_columns(sym, *args, &block)
- ActsAsFu::Connection.connection.change_table(name.tableize) do |t|
+ ActsAsFu::Connection.connection.change_table(table_name) do |t|
t.send(sym, *args)
end
end
@@ -71,4 +69,5 @@ class << klass
alias_method :method_missing, :method_missing_without_columns
end
end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.