Module: Disposable::Twin::Builder

Defined in:
lib/disposable/twin/builder.rb

Overview

Allows building different twin classes.

class SongTwin < Disposable::Twin
  include Builder
  builds ->(model, options) do
    return Hit       if model.is_a? Model::Hit
    return Evergreen if options[:evergreen]
  end
end

SongTwin.build(Model::Hit.new) #=> <Hit>

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/disposable/twin/builder.rb', line 17

def self.included(base)
  base.class_eval do
    include Declarative::Builder

    def self.build(model, options={}) # semi-public.
      build!(self, model, options).new(model, options) # Declarative::Builder::build!.
    end
  end
end