sf

A tiny Crystal library for managing the object status.

Sf (Successes and Failures)

A tiny Crystal library for managing the object status.

Build Status

Installation

Add this to your application's shard.yml:

dependencies:
  sf:
    github: mosop/sf

Code Samples

Storing Statuses

class IsMosop
  extend Sf::AsStatusOwner

  status :success
  status :failure

  getter name : String

  def initialize(@name : String)
  end

  def validate
    if @name == "mosop"
      success!
    else
      failure!
    end
  end
end

mosops = IsMosop::Statuses.new
%w(mosop mosop mosop usop).each do |name|
  mosops.continue do
    IsMosop.new(name).validate
  end
end

mosops[0].status.name # "success"
mosops[1].status.name # "success"
mosops[2].status.name # "success"
mosops[3].status.name # "failure"
mosops[0].name # "mosop"
mosops[1].name # "mosop"
mosops[2].name # "mosop"
mosops[3].name # "usop"
mosops.success[0].name # "mosop"
mosops.success[1].name # "mosop"
mosops.success[2].name # "mosop"
mosops.failure[0].name # "usop"
mosops.has_success? # true
mosops.has_failure? # true

Usage

require "sf"

and see:

Repository

sf

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 0
  • over 7 years ago
  • March 4, 2017
License

MIT License

Links
Synced at

Sun, 24 Nov 2024 17:54:20 GMT

Languages