Created
June 10, 2010 19:00
-
-
Save rossmeissl/433466 to your computer and use it in GitHub Desktop.
Trying to figure out how to disaggregate a model so that its important bits can be open-sourced
This file contains hidden or 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
# This is what we have in our app now: | |
class Automobile < ActiveRecord::Base | |
include Leap # provides #decide classmethod | |
decide :emission do | |
# important stuff described in DSL | |
end | |
# lots of other boring stuff | |
end | |
# But we want the "important stuff" to be open-source | |
# while keeping the "boring stuff" private. | |
# Here are two options. Perhaps there are better ones. | |
# ----------------- | |
# OPTION ONE (only works if model is loaded before gem) | |
# app/models/automobile.rb | |
class Automobile < ActiveRecord::Base | |
# lots of other boring stuff | |
end | |
# in the gem | |
class Automobile | |
include Leap # provides #decide classmethod | |
decide :emission do | |
# important stuff described in DSL | |
end | |
end | |
# ---------------- | |
# OPTION TWO (safer, but more verbose) | |
# app/models/automobile.rb | |
class Automobile < ActiveRecord::Base | |
include BrighterPlanet::Automobile | |
# lots of other boring stuff | |
end | |
# in the gem | |
module BrighterPlanet | |
module Automobile | |
def self.included(base) | |
base.extend ::Leap::Subject # provides #decide classmethod | |
base.decide :emission do | |
# important stuff described in DSL | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment