Skip to content

Instantly share code, notes, and snippets.

@kryzhovnik
Created June 23, 2016 08:24
Show Gist options
  • Save kryzhovnik/b6d0029e0a9b209af88d3ca0eb14d76f to your computer and use it in GitHub Desktop.
Save kryzhovnik/b6d0029e0a9b209af88d3ca0eb14d76f to your computer and use it in GitHub Desktop.
source 'https://rubygems.org'
gem 'dry-types', '0.7.2'
gem 'reform', '2.2.1'
gem 'reform-rails', '0.1.2'
require 'rubygems'
require 'bundler/setup'
require 'dry-types'
require 'reform'
require 'reform/form/active_model/validations'
Reform::Form.class_eval do
include Reform::Form::ActiveModel::Validations
end
class GeoForm < Reform::Form
include Dry::Types.module
property :lat, type: Form::Decimal
property :long, type: Form::Decimal
end
model = Struct.new(:lat, :long).new
form = GeoForm.new(model)
form.validate(lat: '1.2', long: '3.4')
# I except BigDecimal here, but get String
p form.lat.class # => String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment