Skip to content

Instantly share code, notes, and snippets.

@rossmeissl
Created June 10, 2010 19:00
Show Gist options
  • Save rossmeissl/433466 to your computer and use it in GitHub Desktop.
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 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