Created
June 23, 2016 08:24
-
-
Save kryzhovnik/b6d0029e0a9b209af88d3ca0eb14d76f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'dry-types', '0.7.2' | |
gem 'reform', '2.2.1' | |
gem 'reform-rails', '0.1.2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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