Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

r_machine

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

r_machine

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

RMachine

Build Status

class Entity
  include RMachine

  r_machine do |state|
    state.field = :status
    state.initial = :created

    state.on :event_without_param do |event|
      event.change_to :second_state, from: :created
      event.change_to :third_state, from: :second_state
      event.change_to :fourth_state, from: :third_state, if: :is_this_true?
    end

    state.on :event_with_param do |event|
      event.change_to :second_state, from: :created
      event.change_to :third_state, from: :second_state
      event.change_to :fourth_state, from: :third_state, if: :is_param_correct?
    end
  end

  def event_without_param
    super
  end

  def event_with_param(param_to_verify)
    super
  end

  def is_this_true?
    true
  end

  def is_param_correct?(param_to_verify)
    if param_to_verify == :expected
      true
    else
      false
    end
  end
end

entity = Entity.new
puts entity.status # :created

entity.event_without_param
puts entity.status # :second_state

entity.event_with_param(:any)
puts entity.status # :third_state

entity.event_with_param(:any) # raises StateTransactionNotPermittedError

entity.event_with_param(:expected)
puts entity.status # :fourth_state

entity.status = :created
puts entity.status # :created

FAQs

Package last updated on 11 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc