lib/acts-as-joinable.rb in acts-as-joinable-0.0.1.6 vs lib/acts-as-joinable.rb in acts-as-joinable-0.0.1.7

- old
+ new

@@ -1,9 +1,17 @@ module ActsAsJoinable def self.models - @models ||= Dir[Rails.root + "/app/models/*.rb"].collect { |f| File.basename f, '.rb' } + unless @models + if defined?(Rails) + @models = Dir[Dir.pwd + "/app/models/*.rb"].collect { |f| File.basename f, '.rb' } + else + @models = [] + end + end + + @models end def self.models=(value) @models = value end @@ -24,12 +32,12 @@ else write_inheritable_attribute(:acts_as_joinable_config, args) class_inheritable_reader(:acts_as_joinable_config) class_eval do - has_many :parent_relationships, :class_name => 'ActsAsJoinable::Relationship', :as => :child - has_many :child_relationships, :class_name => 'ActsAsJoinable::Relationship', :as => :parent + has_many :parent_relationships, :class_name => 'ActsAsJoinable::Relationship', :as => :child, :dependent => :destroy + has_many :child_relationships, :class_name => 'ActsAsJoinable::Relationship', :as => :parent, :dependent => :destroy def self.joinable? true end @@ -54,6 +62,7 @@ end end ActiveRecord::Base.send(:include, ActsAsJoinable) if defined?(ActiveRecord::Base) +Dir["#{File.dirname(__FILE__)}/../app/models/*"].each { |c| require c if File.extname(c) == ".rb" } Dir["#{File.dirname(__FILE__)}/acts_as_joinable/*"].each { |c| require c if File.extname(c) == ".rb" } \ No newline at end of file