class Quartz::State

Overview

A base class that wraps the state of a model. Automatically extended by models through use of the state macro.

See Stateful#state.

Direct Known Subclasses

Defined in:

quartz/json.cr
quartz/state.cr

Constructors

Instance Method Summary

Macro Summary

Instance methods inherited from class Reference

==(other : Quartz::Any) ==

Instance methods inherited from class Object

===(other : Quartz::Any) ===

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]
def self.new(**kwargs) #

[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


[View source]
def ==(other) #
Description copied from class Reference

Returns false (other can only be a Value here).


[View source]
def clone #

Returns a copy of self with all instance variables cloned.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


[View source]
def inspect(io) #

[View source]
def to_hash #

[View source]
def to_json(json : JSON::Builder) #

[View source]
def to_named_tuple #

[View source]

Macro Detail

macro var(name, &block) #

The var macro defines a state variable for the State of a model. Its primary goal is to generate convenient getters and setters for the model among other purposes.

It is intended to be used within a block provided with the Stateful#state macro.

See also Stateful#state.

Usage

var must receive a type declaration which will be used to declare an instance variable, a getter and a setter.

Default values must be declared using the type declaration notation or through a block (lazy initialization) :

state do
  var foo : Int32 = 42
  var bar : Int32 { (rand * 100 + 1).to_i32 }
  var quz : Int32 { foo * 42 }
end

Note from previous example that the initialization block of quz is allowed to reference the value of another state variable.


[View source]