Module: Shale::Builder

Extended by:
T::Helpers, T::Sig
Defined in:
lib/shale/builder.rb,
lib/shale/builder/version.rb

Overview

It’s meant to be included in subclasses of ‘Shale::Mapper` to provide an easier way of building instances.

Example:

require 'shale/builder'

class PaymentInstrument < Shale::Mapper
  include Shale::Builder

  attribute :number, Shale::Type::String
  attribute :expiration_year, ::Shale::Type::Integer
  attribute :expiration_month, ::Shale::Type::Integer
end

class Transaction < ::Shale::Mapper
  include Shale::Builder

  attribute :cvv_code, Shale::Type::String
  attribute :payment_instrument, PaymentInstrument
end

transaction = Transaction.build do |t|
    t.cvv_code = '123'
    t.payment_instrument do |p|
        p.number = '4242424242424242'
        p.expiration_year = 2045
        p.expiration_month = 12
    end
end

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
'0.2.2'

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



50
51
52
53
# File 'lib/shale/builder.rb', line 50

def included(mod)
  mod.extend ClassMethods
  Builder.prepare_mod(mod)
end

.prepare_mod(mod) ⇒ Object



58
59
60
61
62
# File 'lib/shale/builder.rb', line 58

def prepare_mod(mod)
  builder_methods_module = ::Module.new
  mod.instance_variable_set :@builder_methods_module, builder_methods_module
  mod.include builder_methods_module
end