Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rails_plugin_creation moved to rails/plugin_creation
- Loading branch information
Showing
1 changed file
with
50 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
--- | ||
rails_plugin_creation: |- | ||
require 'active_record' | ||
module Foo | ||
module Acts #:nodoc: | ||
module Fox #:nodoc: | ||
def self.included(mod) | ||
mod.extend(ClassMethods) | ||
end | ||
# declare the class level helper methods which | ||
# will load the relevant instance methods | ||
# defined below when invoked | ||
module ClassMethods | ||
def acts_as_fox | ||
class_eval do | ||
extend Foo::Acts::Fox::SingletonMethods | ||
end | ||
include Foo::Acts::Fox::InstanceMethods | ||
end | ||
end | ||
# Adds a catch_chickens class method which finds | ||
# all records which have a 'chickens' field set | ||
# to true. | ||
module SingletonMethods | ||
def catch_chickens | ||
find(:all, :conditions => ['chickens = ?', true]) | ||
end | ||
# etc... | ||
end | ||
# Adds instance methods. | ||
module InstanceMethods | ||
def eat_chicken | ||
puts "Fox with ID #{self.id} just ate a chicken" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# reopen ActiveRecord and include all the above to make | ||
# them available to all our models if they want it | ||
ActiveRecord::Base.class_eval do | ||
include Foo::Acts::Fox | ||
rails::plugin_creation: |- | ||
|
||
require 'active_record' | ||
|
||
module Foo | ||
module Acts #:nodoc: | ||
module Fox #:nodoc: | ||
|
||
def self.included(mod) | ||
mod.extend(ClassMethods) | ||
end | ||
|
||
# declare the class level helper methods which | ||
# will load the relevant instance methods | ||
# defined below when invoked | ||
module ClassMethods | ||
def acts_as_fox | ||
class_eval do | ||
extend Foo::Acts::Fox::SingletonMethods | ||
end | ||
include Foo::Acts::Fox::InstanceMethods | ||
end | ||
end | ||
|
||
# Adds a catch_chickens class method which finds | ||
# all records which have a 'chickens' field set | ||
# to true. | ||
module SingletonMethods | ||
def catch_chickens | ||
find(:all, :conditions => ['chickens = ?', true]) | ||
end | ||
# etc... | ||
end | ||
|
||
# Adds instance methods. | ||
module InstanceMethods | ||
def eat_chicken | ||
puts "Fox with ID #{self.id} just ate a chicken" | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
||
# reopen ActiveRecord and include all the above to make | ||
# them available to all our models if they want it | ||
|
||
ActiveRecord::Base.class_eval do | ||
include Foo::Acts::Fox | ||
end |