{"action":"created","comment":{"url":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/comments/93739931","pull_request_review_id":14273508,"id":93739931,"diff_hunk":"@@ -0,0 +1,81 @@\n+---\n+title: Input Preprocessing\n+layout: gem-single\n+---\n+\n+Sometimes, the data coming from outside needs to be preprocessed before being validated. Think of extraneous spaces before or after a string, for example.\n+\n+### Preprocessing names to remove spaces\n+\n+In the context of a web application form, it is common to ask for people's names. The name should not contain spaces before or after the other characters. It would be possible to reject such strings as invalid, but that would make the application harder to use. Instead, we can let dry-validation preprocess the input to remove such spaces. To that end, we will create a new type of validator:\n+\n+```ruby\n+require \"dry-validation\"\n+\n+module Types\n+  include Dry::Types.module\n+\n+  Name = Types::String.constructor do |str|\n+    str ? str.strip.chomp : str\n+  end\n+end\n+\n+SignUpForm = Dry::Validation.Form do\n+  configure do\n+    config.type_specs = true\n+  end\n+\n+  required(:email, :string).filled(format?: /.@.+[.][a-z]{2,}/i)\n+  required(:name, Types::Name).filled(min_size?: 1)\n+  required(:password, :string).filled(min_size?: 6)\n+end\n+\n+result = SignUpForm.call(\n+  \"name\" => \"\\t François \\n\",\n+  \"email\" => \"francois@teksol.info\",\n+  \"password\" => \"some password\")\n+\n+result.success?\n+# true\n+\n+result.output.fetch(:name)","path":"source/gems/dry-validation/input-preprocessing.html.md","position":41,"original_position":41,"commit_id":"f5095015866d5baf54e226b342ecbf46cbb6f810","original_commit_id":"f5095015866d5baf54e226b342ecbf46cbb6f810","user":{"login":"solnic","id":1066,"avatar_url":"https://avatars.githubusercontent.com/u/1066?v=3","gravatar_id":"","url":"https://api.github.com/users/solnic","html_url":"https://github.com/solnic","followers_url":"https://api.github.com/users/solnic/followers","following_url":"https://api.github.com/users/solnic/following{/other_user}","gists_url":"https://api.github.com/users/solnic/gists{/gist_id}","starred_url":"https://api.github.com/users/solnic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solnic/subscriptions","organizations_url":"https://api.github.com/users/solnic/orgs","repos_url":"https://api.github.com/users/solnic/repos","events_url":"https://api.github.com/users/solnic/events{/privacy}","received_events_url":"https://api.github.com/users/solnic/received_events","type":"User","site_admin":false},"body":"Actually, this could just be `result[:name]` as `Result` objects are hash-like. Also, `output` is going to be deprecated prior 1.0.0 in favor of `to_h`","created_at":"2016-12-23T08:30:22Z","updated_at":"2016-12-23T08:30:22Z","html_url":"https://github.com/dry-rb/dry-rb.org/pull/129#discussion_r93739931","pull_request_url":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/129","_links":{"self":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/comments/93739931"},"html":{"href":"https://github.com/dry-rb/dry-rb.org/pull/129#discussion_r93739931"},"pull_request":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/129"}}},"pull_request":{"url":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/129","id":99178288,"html_url":"https://github.com/dry-rb/dry-rb.org/pull/129","diff_url":"https://github.com/dry-rb/dry-rb.org/pull/129.diff","patch_url":"https://github.com/dry-rb/dry-rb.org/pull/129.patch","issue_url":"https://api.github.com/repos/dry-rb/dry-rb.org/issues/129","number":129,"state":"open","locked":false,"title":"Explain how to do input preprocessing","user":{"login":"francois","id":247,"avatar_url":"https://avatars.githubusercontent.com/u/247?v=3","gravatar_id":"","url":"https://api.github.com/users/francois","html_url":"https://github.com/francois","followers_url":"https://api.github.com/users/francois/followers","following_url":"https://api.github.com/users/francois/following{/other_user}","gists_url":"https://api.github.com/users/francois/gists{/gist_id}","starred_url":"https://api.github.com/users/francois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francois/subscriptions","organizations_url":"https://api.github.com/users/francois/orgs","repos_url":"https://api.github.com/users/francois/repos","events_url":"https://api.github.com/users/francois/events{/privacy}","received_events_url":"https://api.github.com/users/francois/received_events","type":"User","site_admin":false},"body":"Based on discussion in [How to skip blanks in nested array?](https://discuss.dry-rb.org/t/how-to-skip-blanks-in-nested-array/177) with @solnic, I submit the following for review.\r\n\r\nI chose to create a new section for preprocessing because when I was searching the dry-validation site, I would have immediately understood that preprocessing is what I needed.\r\n\r\nI think it would also be useful to explain how to create an Array of Name values. I haven't done so because I'm not sure how to do that yet. If someone could point me in the right direction, I would be happy to extend this PR to include such mixing-and-matching of types.","created_at":"2016-12-22T22:16:32Z","updated_at":"2016-12-23T08:30:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c0461d7eb0cc4ba9b23bbe3080a734623d09bad7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/129/commits","review_comments_url":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/129/comments","review_comment_url":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dry-rb/dry-rb.org/issues/129/comments","statuses_url":"https://api.github.com/repos/dry-rb/dry-rb.org/statuses/f5095015866d5baf54e226b342ecbf46cbb6f810","head":{"label":"francois:explain-input-preprocessing","ref":"explain-input-preprocessing","sha":"f5095015866d5baf54e226b342ecbf46cbb6f810","user":{"login":"francois","id":247,"avatar_url":"https://avatars.githubusercontent.com/u/247?v=3","gravatar_id":"","url":"https://api.github.com/users/francois","html_url":"https://github.com/francois","followers_url":"https://api.github.com/users/francois/followers","following_url":"https://api.github.com/users/francois/following{/other_user}","gists_url":"https://api.github.com/users/francois/gists{/gist_id}","starred_url":"https://api.github.com/users/francois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francois/subscriptions","organizations_url":"https://api.github.com/users/francois/orgs","repos_url":"https://api.github.com/users/francois/repos","events_url":"https://api.github.com/users/francois/events{/privacy}","received_events_url":"https://api.github.com/users/francois/received_events","type":"User","site_admin":false},"repo":{"id":77178951,"name":"dry-rb.org","full_name":"francois/dry-rb.org","owner":{"login":"francois","id":247,"avatar_url":"https://avatars.githubusercontent.com/u/247?v=3","gravatar_id":"","url":"https://api.github.com/users/francois","html_url":"https://github.com/francois","followers_url":"https://api.github.com/users/francois/followers","following_url":"https://api.github.com/users/francois/following{/other_user}","gists_url":"https://api.github.com/users/francois/gists{/gist_id}","starred_url":"https://api.github.com/users/francois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francois/subscriptions","organizations_url":"https://api.github.com/users/francois/orgs","repos_url":"https://api.github.com/users/francois/repos","events_url":"https://api.github.com/users/francois/events{/privacy}","received_events_url":"https://api.github.com/users/francois/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/francois/dry-rb.org","description":"The official website of dryrb org","fork":true,"url":"https://api.github.com/repos/francois/dry-rb.org","forks_url":"https://api.github.com/repos/francois/dry-rb.org/forks","keys_url":"https://api.github.com/repos/francois/dry-rb.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/francois/dry-rb.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/francois/dry-rb.org/teams","hooks_url":"https://api.github.com/repos/francois/dry-rb.org/hooks","issue_events_url":"https://api.github.com/repos/francois/dry-rb.org/issues/events{/number}","events_url":"https://api.github.com/repos/francois/dry-rb.org/events","assignees_url":"https://api.github.com/repos/francois/dry-rb.org/assignees{/user}","branches_url":"https://api.github.com/repos/francois/dry-rb.org/branches{/branch}","tags_url":"https://api.github.com/repos/francois/dry-rb.org/tags","blobs_url":"https://api.github.com/repos/francois/dry-rb.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/francois/dry-rb.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/francois/dry-rb.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/francois/dry-rb.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/francois/dry-rb.org/statuses/{sha}","languages_url":"https://api.github.com/repos/francois/dry-rb.org/languages","stargazers_url":"https://api.github.com/repos/francois/dry-rb.org/stargazers","contributors_url":"https://api.github.com/repos/francois/dry-rb.org/contributors","subscribers_url":"https://api.github.com/repos/francois/dry-rb.org/subscribers","subscription_url":"https://api.github.com/repos/francois/dry-rb.org/subscription","commits_url":"https://api.github.com/repos/francois/dry-rb.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/francois/dry-rb.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/francois/dry-rb.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/francois/dry-rb.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/francois/dry-rb.org/contents/{+path}","compare_url":"https://api.github.com/repos/francois/dry-rb.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/francois/dry-rb.org/merges","archive_url":"https://api.github.com/repos/francois/dry-rb.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/francois/dry-rb.org/downloads","issues_url":"https://api.github.com/repos/francois/dry-rb.org/issues{/number}","pulls_url":"https://api.github.com/repos/francois/dry-rb.org/pulls{/number}","milestones_url":"https://api.github.com/repos/francois/dry-rb.org/milestones{/number}","notifications_url":"https://api.github.com/repos/francois/dry-rb.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/francois/dry-rb.org/labels{/name}","releases_url":"https://api.github.com/repos/francois/dry-rb.org/releases{/id}","deployments_url":"https://api.github.com/repos/francois/dry-rb.org/deployments","created_at":"2016-12-22T22:06:29Z","updated_at":"2016-12-22T22:06:32Z","pushed_at":"2016-12-22T22:11:57Z","git_url":"git://github.com/francois/dry-rb.org.git","ssh_url":"git@github.com:francois/dry-rb.org.git","clone_url":"https://github.com/francois/dry-rb.org.git","svn_url":"https://github.com/francois/dry-rb.org","homepage":"http://dry-rb.org/","size":4808,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dry-rb:master","ref":"master","sha":"8978cc0499c5b99afdc6b15ef5b91cf0694175fd","user":{"login":"dry-rb","id":11280820,"avatar_url":"https://avatars.githubusercontent.com/u/11280820?v=3","gravatar_id":"","url":"https://api.github.com/users/dry-rb","html_url":"https://github.com/dry-rb","followers_url":"https://api.github.com/users/dry-rb/followers","following_url":"https://api.github.com/users/dry-rb/following{/other_user}","gists_url":"https://api.github.com/users/dry-rb/gists{/gist_id}","starred_url":"https://api.github.com/users/dry-rb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dry-rb/subscriptions","organizations_url":"https://api.github.com/users/dry-rb/orgs","repos_url":"https://api.github.com/users/dry-rb/repos","events_url":"https://api.github.com/users/dry-rb/events{/privacy}","received_events_url":"https://api.github.com/users/dry-rb/received_events","type":"Organization","site_admin":false},"repo":{"id":50876871,"name":"dry-rb.org","full_name":"dry-rb/dry-rb.org","owner":{"login":"dry-rb","id":11280820,"avatar_url":"https://avatars.githubusercontent.com/u/11280820?v=3","gravatar_id":"","url":"https://api.github.com/users/dry-rb","html_url":"https://github.com/dry-rb","followers_url":"https://api.github.com/users/dry-rb/followers","following_url":"https://api.github.com/users/dry-rb/following{/other_user}","gists_url":"https://api.github.com/users/dry-rb/gists{/gist_id}","starred_url":"https://api.github.com/users/dry-rb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dry-rb/subscriptions","organizations_url":"https://api.github.com/users/dry-rb/orgs","repos_url":"https://api.github.com/users/dry-rb/repos","events_url":"https://api.github.com/users/dry-rb/events{/privacy}","received_events_url":"https://api.github.com/users/dry-rb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dry-rb/dry-rb.org","description":"The official website of dryrb org","fork":false,"url":"https://api.github.com/repos/dry-rb/dry-rb.org","forks_url":"https://api.github.com/repos/dry-rb/dry-rb.org/forks","keys_url":"https://api.github.com/repos/dry-rb/dry-rb.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dry-rb/dry-rb.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dry-rb/dry-rb.org/teams","hooks_url":"https://api.github.com/repos/dry-rb/dry-rb.org/hooks","issue_events_url":"https://api.github.com/repos/dry-rb/dry-rb.org/issues/events{/number}","events_url":"https://api.github.com/repos/dry-rb/dry-rb.org/events","assignees_url":"https://api.github.com/repos/dry-rb/dry-rb.org/assignees{/user}","branches_url":"https://api.github.com/repos/dry-rb/dry-rb.org/branches{/branch}","tags_url":"https://api.github.com/repos/dry-rb/dry-rb.org/tags","blobs_url":"https://api.github.com/repos/dry-rb/dry-rb.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dry-rb/dry-rb.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dry-rb/dry-rb.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/dry-rb/dry-rb.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dry-rb/dry-rb.org/statuses/{sha}","languages_url":"https://api.github.com/repos/dry-rb/dry-rb.org/languages","stargazers_url":"https://api.github.com/repos/dry-rb/dry-rb.org/stargazers","contributors_url":"https://api.github.com/repos/dry-rb/dry-rb.org/contributors","subscribers_url":"https://api.github.com/repos/dry-rb/dry-rb.org/subscribers","subscription_url":"https://api.github.com/repos/dry-rb/dry-rb.org/subscription","commits_url":"https://api.github.com/repos/dry-rb/dry-rb.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/dry-rb/dry-rb.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/dry-rb/dry-rb.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/dry-rb/dry-rb.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/dry-rb/dry-rb.org/contents/{+path}","compare_url":"https://api.github.com/repos/dry-rb/dry-rb.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dry-rb/dry-rb.org/merges","archive_url":"https://api.github.com/repos/dry-rb/dry-rb.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dry-rb/dry-rb.org/downloads","issues_url":"https://api.github.com/repos/dry-rb/dry-rb.org/issues{/number}","pulls_url":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls{/number}","milestones_url":"https://api.github.com/repos/dry-rb/dry-rb.org/milestones{/number}","notifications_url":"https://api.github.com/repos/dry-rb/dry-rb.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dry-rb/dry-rb.org/labels{/name}","releases_url":"https://api.github.com/repos/dry-rb/dry-rb.org/releases{/id}","deployments_url":"https://api.github.com/repos/dry-rb/dry-rb.org/deployments","created_at":"2016-02-01T22:42:07Z","updated_at":"2016-12-22T02:01:11Z","pushed_at":"2016-12-22T22:49:16Z","git_url":"git://github.com/dry-rb/dry-rb.org.git","ssh_url":"git@github.com:dry-rb/dry-rb.org.git","clone_url":"https://github.com/dry-rb/dry-rb.org.git","svn_url":"https://github.com/dry-rb/dry-rb.org","homepage":"http://dry-rb.org/","size":5046,"stargazers_count":19,"watchers_count":19,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":39,"mirror_url":null,"open_issues_count":31,"forks":39,"open_issues":31,"watchers":19,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/129"},"html":{"href":"https://github.com/dry-rb/dry-rb.org/pull/129"},"issue":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/issues/129"},"comments":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/issues/129/comments"},"review_comments":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/129/comments"},"review_comment":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/pulls/129/commits"},"statuses":{"href":"https://api.github.com/repos/dry-rb/dry-rb.org/statuses/f5095015866d5baf54e226b342ecbf46cbb6f810"}}}}
{"actor":{"display_login":"solnic"}}