Sha256: 7d7b3beda480fcbbb6e80e321646a0146ebb0ff9b9d3fb6e64591c7f8c8090ea

Contents?: true

Size: 731 Bytes

Versions: 8

Compression:

Stored size: 731 Bytes

Contents

require "declarative/builder"

module Disposable
  class Twin
    # 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>
    module Builder
      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
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
disposable-0.5.0 lib/disposable/twin/builder.rb
disposable-0.4.7 lib/disposable/twin/builder.rb
disposable-0.4.6 lib/disposable/twin/builder.rb
disposable-0.4.5 lib/disposable/twin/builder.rb
disposable-0.4.4 lib/disposable/twin/builder.rb
disposable-0.4.3 lib/disposable/twin/builder.rb
disposable-0.4.2 lib/disposable/twin/builder.rb
disposable-0.4.1 lib/disposable/twin/builder.rb