GithubHelp home page GithubHelp logo

boa's Introduction

Boa - The Smart Constructor

This is a work in progress. It is not ready for production use.

Usage

class Person < T::Struct
  include Boa

  prop :id,         UUID
  prop :name,       String, length: 1..50
  prop :email,      T.nilable(Email)
  prop :admin,      T.nilable(T::Boolean)
  prop :birth_date, T.nilable(Date), includes: Date.new(1900)..Date.today
  prop :created_at, DateTime, factory: -> { DateTime.now }
end

# Person.new actually does a few things:
# - Constructs the data using the *real* constructor
# - Validates the object
# - If valid it returns a Person
# - If invalid it returns a Person::Invalid that wraps the data, containing
#   all the errors for the Person. Use with Ruby 3 case pattern matching.
person = Person.new(id: id, name: 'Dan Kubb', email: '[email protected]')

# Expected accessor usage
puts person.created_at  # => returns DateTime.now
puts person.email       # => returns an Email object (or nil when no email is provided)

# Ruby 3 case pattern matching
valid_person =
  case person
  in Person if person.admin
    person                                              # person is valid *and* an admin
  in Person
    person                                              # person is valid
  in Person::Invalid                                    # could also use else here
    fail "person is invalid: #{person.errors.inspect}"  # person is invalid
  end

Installation

Add this line to your application's Gemfile:

gem 'boa'

And then execute:

bundle

Or install it yourself as:

gem install boa

boa's People

Contributors

dkubb avatar dependabot[bot] avatar

Stargazers

Sam Moore avatar

Watchers

 avatar  avatar

boa's Issues

Refactor #freeze to to be DRY

The Boa::ClassMethods#freeze and Boa::Type#freeze implementations are the same

It could be moved into a separate module and mixed into both locations.

Add shared tests for Equality

The Boa and Boa::Test Equality method tests do not share any common setup at the moment, and should be extracted into a single set of shared tests that exercise every dimension.

Use spoom in Github Actions

Use spoom to:

  • Bump all files to strong if not already (and check to see if anything changed)
  • Measure Typing coverage over time

Change tests to support sorbet

The first step will be to switch to normal minitest to see if the spec interface is what makes it hard to enable sorbet type checking.

The next step would be to port to rspec. There is an rspec-sorbet plugin that attempts to make them work together better.

The ideal would be to reach strong level across all tests, but even strict or just true would be an improvement. Tests should be held to the same high standards as the library code, so it is not acceptable that we cannot use sorbet to type verify tests and support files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.