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
# If you use amoeba (https://github.com/amoeba-rb/amoeba) for cloning your | |
# ActiveRecord objects this concern should be useful, it allows you properfly inherit | |
# associations if you use (Single Table) Inheritance. | |
# | |
# Just do something like: | |
# | |
# class SomeTable < ActiveRecord::Base | |
# has_many :somethings | |
# | |
# duplicate_this do |
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
#!/usr/bin/env ruby | |
require_relative 'builder' | |
v1 = Versioning::Builder.build(1) | |
v1.first_name = 'Mario' | |
v1.last_name = 'Carrion' | |
puts v1.columns | |
puts v1.values |
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
require_relative 'version1' | |
require_relative 'version2' | |
module Versioning | |
class Builder | |
class << self | |
def build(version) | |
version = version.to_i |
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
#!/usr/bin/env ruby | |
require_relative 'version2' | |
v1 = Version1.new | |
v1.first_name = 'Mario' | |
v1.last_name = 'Carrion' | |
puts v1.columns | |
puts v1.values |
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
require_relative 'version1' | |
class Version2 < Version1 | |
versioned_accessor :age, :integer, nil: true | |
def version | |
2 | |
end | |
end |
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
#!/usr/bin/env ruby | |
require_relative 'base' | |
require_relative 'version1' | |
x = Version1.new | |
x.first_name = 'Mario' | |
x.last_name = 'Carrion' | |
puts x.columns |
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
require_relative 'base' | |
class Version1 < Versioning::Base | |
versioned_accessor :last_name, :string, length: 20, nil: false | |
versioned_accessor :first_name, :string, length: 20, nil: false | |
def version | |
1 | |
end | |
end |
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
module Versioning | |
class Base | |
PREFIX = '__versioned' | |
LENGTH = PREFIX.length | |
def version | |
raise ArgumentError.new('not defined') | |
end |
NewerOlder