Skip to content

Instantly share code, notes, and snippets.

@nov

nov/gist:125623

Created Jun 8, 2009
Embed
What would you like to do?
# environment.rb
VERSION_DEFAULT = Version1
# user.rb
class User
include Builder::UserMarkup
end
# builder/base.rb
module Builder
class Base
def to_markup(markup, options = {})
case options[:version]
when 'v3'
Version3.to_markup(self, markup, options)
when 'v2'
Version2.to_markup(self, markup, options)
when 'v1'
Version1.to_markup(self, markup, options)
else # Default
DefaultVersion.to_markup(self, markup, options)
end
end
def to_xml
self.to_markup(Builder::XmlBuilder.new, options)
end
def to_json
self.to_markup(Builder::JsonBuilder.new, options)
end
end
end
# builder/user_markup.rb
module Builder
class UserMarkup < Base
class Version1
def to_markup(user, markup, options = {})
end
end
class Version2
def to_markup(user, markup, options = {})
end
end
class Version3
def to_markup(user, markup, options = {})
end
end
class DefaultVersion < VERSION_DEFAULT
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.