Module: Plushie::Model

Defined in:
lib/plushie/model.rb

Overview

Convenience wrapper around Data.define that adds a #with method for partial updates, producing a new immutable instance.

Model = Plushie::Model.define(:count, :name) m = Model.new(count: 0, name: "test") m.with(count: 1) # => Model(count: 1, name: "test")

Instances are frozen by default (inherited from Data). Attempting to mutate raises FrozenError.

Defined Under Namespace

Modules: Extensions

Class Method Summary collapse

Class Method Details

.define(*fields) ⇒ Object

Define a new model class with the given attributes.



15
16
17
18
19
# File 'lib/plushie/model.rb', line 15

def self.define(*fields)
  klass = Data.define(*fields)
  klass.include(Extensions)
  klass
end