Sha256: e2cc0469ab35e25299e7e62f07b8649aed2bb32ea5b64b01c230580095148d42

Contents?: true

Size: 760 Bytes

Versions: 3

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

class Acfs::Resource
  #
  # Initialization drop-in for pre-4.0 ActiveModel.
  #
  module Initialization
    #
    # @api public
    #
    # Initializes a new model with the given `params`.
    #
    # @example
    #   class User < Acfs::Resource
    #     attribute :name
    #     attribute :email, default: ->{ "#{name}@dom.tld" }
    #     attribute :age, :integer, default: 18
    #   end
    #
    #   user = User.new({name: 'bob'})
    #   user.name  # => "bob"
    #   user.email # => "bob@dom.tld"
    #   user.age   # => 18
    #
    # @param attributes [Hash{Symbol => Object}] Attributes to set on resource.
    #
    def initialize(attributes = {})
      write_attributes(attributes) if attributes
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acfs-2.0.0 lib/acfs/resource/initialization.rb
acfs-1.7.0 lib/acfs/resource/initialization.rb
acfs-1.6.0 lib/acfs/resource/initialization.rb