Permalink
Browse files

Reorganized files. requiring "acts_as_fu" will now automatically include

the ActsAsFu module. To prevent auto-including, require "acts_as_fu/base".

Calling #build_model now returns the newly created klass.
  • Loading branch information...
1 parent 3394ce7 commit 4563a96a132417abaa6a83a6b16897b9cd65d958 @nakajima committed Jan 22, 2009
Showing with 21 additions and 9 deletions.
  1. +2 −2 acts_as_fu.gemspec
  2. +3 −5 lib/acts_as_fu.rb
  3. +6 −0 lib/acts_as_fu/{helper.rb → base.rb}
  4. +0 −2 lib/acts_as_fu/constants.rb
  5. +10 −0 spec/acts_as_fu_spec.rb
View
4 acts_as_fu.gemspec
@@ -2,13 +2,13 @@
Gem::Specification.new do |s|
s.name = %q{acts_as_fu}
- s.version = "0.0.2"
+ s.version = "0.0.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Pat Nakajima"]
s.date = %q{2008-10-26}
s.email = %q{patnakajima@gmail.com}
- s.files = ["lib/acts_as_fu", "lib/acts-as-fu.rb", "lib/acts_as_fu/constants.rb", "lib/acts_as_fu/helper.rb", "lib/acts_as_fu.rb"]
+ s.files = ["lib/acts_as_fu", "lib/acts-as-fu.rb", "lib/acts_as_fu/base.rb", "lib/acts_as_fu.rb"]
s.has_rdoc = true
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.0}
View
8 lib/acts_as_fu.rb
@@ -1,7 +1,5 @@
-$LOAD_PATH << File.dirname(__FILE__) + '/acts_as_fu'
+$LOAD_PATH << File.dirname(__FILE__)
-module ActsAsFu
- VERSION = '0.0.2'
-end
+require 'acts_as_fu/base'
-%w(rubygems activerecord constants helper).each { |lib| require lib }
+include ActsAsFu
View
6 lib/acts_as_fu/helper.rb → lib/acts_as_fu/base.rb
@@ -1,3 +1,8 @@
+%w(rubygems activerecord).each { |lib| require lib }
+
+RAILS_ROOT = File.join(File.dirname(__FILE__), '..') unless defined?(RAILS_ROOT)
+RAILS_ENV = 'test' unless defined?(RAILS_ENV)
+
module ActsAsFu
class << self
attr_reader :log
@@ -31,6 +36,7 @@ def set_class!(name, super_class, &block)
Object.const_set(klass_name, klass)
model_eval(klass, &block)
+ klass
end
def connect!
View
2 lib/acts_as_fu/constants.rb
@@ -1,2 +0,0 @@
-RAILS_ROOT = File.join(File.dirname(__FILE__), '..') unless defined?(RAILS_ROOT)
-RAILS_ENV = 'test' unless defined?(RAILS_ENV)
View
10 spec/acts_as_fu_spec.rb
@@ -18,6 +18,16 @@ def self.awesome?; true end
end
end
+ describe "build_models" do
+ it "returns the new klass" do
+ klass = build_model(:people) do
+ string :name
+ end
+
+ klass.should == Person
+ end
+ end
+
describe "without building a model" do
it "asplodes" do
proc {

4 comments on commit 4563a96

@grosser

this may make it easier to use, but also strongly increases coupling which can never be good.

@nakajima
Owner

Are you referring to the auto-inclusion? Coupling to what?

I made this choice because I was tired of always needing to require the module scratch windows or irb. In my spec helpers, I just require ‘acts_as_fu/base’ and I can include the module explicitly.

@nakajima
Owner

Pardon the typos. I’m typing from an iPhone.

@grosser

i know, its a bit of a hassle to always use the extra include.

its cupled to the environment, i cannot simply extend acts as fu or have another method named the same as the included ones, without thinking about how to circumvent auto-inclusion

how about: require ‘acts_as_fu/include’, which then performs require+include

Pardon the typos. I’m typing from an keyboard ;)

Please sign in to comment.