Sha256: f81f81d4379d77c23acc6ee46ebb1a9970ecfc3f6249dd689844f64050e0d0d7
Contents?: true
Size: 1.04 KB
Versions: 5
Compression:
Stored size: 1.04 KB
Contents
# frozen_string_literal: true class Sinclair # @author darthjee # @api public # # Class methods for {Sinclair} module ClassMethods # Runs build using a block for adding the methods # # The block is executed adding the methods and after the builder # runs build building all the methods # # @param (see Sinclair#initialize) # @param block [Proc] block to be executed by the builder # in order to add the methods before running build # # @yield an instance of a builder ({Sinclair}) # # @return (see Sinclair#build) # # @example Simple usage # class MyPerson # end # # Sinclair.build(model_class) do # add_method(:random_name, cached: true) do # "John #{Random.rand(1000)} Doe" # end # end # # model = MyPerson.new # # model.random_name # returns 'John 803 Doe' def build(klass, options = {}, &block) new(klass, options).tap do |builder| builder.instance_eval(&block) end.build end end end
Version data entries
5 entries across 5 versions & 1 rubygems