0.0
No commit activity in last 3 years
No release in over 3 years
FormalWear helps you create Form Objects with required and optional attributes and gets all fancy widdit.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.13.1
>= 0

Runtime

>= 3.0.20
~> 0.5.0
 Project Readme

FormalWear

Build Status Code Climate Coverage Status Dependency Status

"You're going to like the way you look. I guarantee it."

FormalWear helps you create Form Objects with required and optional attributes and gets all fancy widdit.

Installation

Add this line to your application's Gemfile:

gem 'formal_wear'

And then execute:

$ bundle

Or install it yourself as:

$ gem install formal_wear

Usage

class TestFormalWear
  include FormalWear

  required_attr moms_id: {
    name: "Your mom's id",
    type: :text,
    source: ->(s) { s.primary.thing_to_be_configured },
  }

  required_attr docs_id: {
    name: "Your doc's id",
    type: :text,
    source: ->(s) { s.primary.dependent_object.another_thing_to_be_configured },
    store: :set_my_docs_id
  }

  required_attr lambda_lambda_lambda: {
    name: 'Revenge Of The Nerds!',
    type: :text,
    source: ->(s) { s.get_pledged },
    store:  ->(s) { s.got_lambda? }
  }

  protected

  def after_save
    # no-op
  end

  def set_moms_id
    # no-op
  end

  def set_my_docs_id
    # no-op
  end

  def got_lambda?
    # no-op
  end

  def get_pledged
    primary.dependent_object.another_thing_to_be_configured
  end
end

Including FormalWear into your class adds a required_attrs and required_attr methods. Specifying a required attr, like so:

  required_attr lambda_lambda_lambda: {
    name: 'Revenge Of The Nerds!',
    type: :text,
    source: ->(s) { s.get_pledged },
    store:  ->(s) { s.got_lambda? }
  }

adds the attribute to the list of required_fields, and populates it from the source specified in its hash when your class is initialized.

Instantiating

  TestFormalWear.new(primary_object)

... where primary object you will use to fetch values from their source. (TODO: add support for multiple sources)

Specifying sources

The source option takes a lambda that accepts self as its argument. This allows you to use a method within your class to fetch the information needed from its source, or to directly fetch it using the primary object set when you instantiated the class.

Source is a required attribute, but it can return nil if you feel so inclined. It's a bit like going commando under that tuxedo, though.

TODO

  • Update this readme
  • (Maybe?) Add helper methods for providing data for working with forms

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request