mutations 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ branches:
6
+ only:
7
+ - master
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'http://rubygems.org'
2
+ gemspec
2
3
 
3
4
  gem 'minitest', '~> 4.0'
4
5
  gem 'activesupport'
data/Gemfile.lock CHANGED
@@ -1,3 +1,9 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mutations (0.5.0)
5
+ activesupport
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
@@ -7,6 +13,7 @@ GEM
7
13
  i18n (0.6.1)
8
14
  minitest (4.1.0)
9
15
  multi_json (1.3.6)
16
+ rake (0.9.2.2)
10
17
 
11
18
  PLATFORMS
12
19
  ruby
@@ -14,3 +21,5 @@ PLATFORMS
14
21
  DEPENDENCIES
15
22
  activesupport
16
23
  minitest (~> 4.0)
24
+ mutations!
25
+ rake
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Jonathan Novak
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Mutations
2
2
 
3
+ [![Build Status](https://travis-ci.org/cypriss/mutations.png)](https://travis-ci.org/cypriss/mutations)
4
+
3
5
  Compose your business logic into commands that sanitize and validate input. Write safe, reusable, and maintainable code for Ruby and Rails apps.
4
6
 
5
7
  ## Installation
@@ -44,7 +46,7 @@ def create
44
46
  if outcome.success?
45
47
  render json: {message: "Great success, #{outcome.result.name}!"}
46
48
  else
47
- render json: outcome.errors.symbolic
49
+ render json: outcome.errors.symbolic, status: 422
48
50
  end
49
51
  end
50
52
  ```
@@ -53,11 +55,11 @@ Some things to note about the example:
53
55
 
54
56
  * We don't need attr_accessible or strong_attributes to protect against mass assignment attacks
55
57
  * We're guaranteed that within execute, the inputs will be the correct data types, even if they needed some coercion (all strings are stripped by default, and strings like "1" / "0" are converted to true/false for newsletter_subscribe)
56
- * We don't need ActiveRecord/ActiveModel validations
57
- * We don't need Callbacks on our models -- everything is in the execute method (helper methods are also encouraged).
58
- * We don't use accepts_nested_attributes_for, even though multiple AR models are created.
58
+ * We don't need ActiveRecord validations
59
+ * We don't need callbacks on our models -- everything is in the execute method (helper methods are also encouraged)
60
+ * We don't use accepts_nested_attributes_for, even though multiple ActiveRecord models are created
59
61
  * This code is completely re-usable in other contexts (need an API?)
60
- * The inputs to this 'function' are documented by default -- the bare minimum to use it (name and email) are documented, as are 'extras' (newsletter_subscribe).
62
+ * The inputs to this 'function' are documented by default -- the bare minimum to use it (name and email) are documented, as are 'extras' (newsletter_subscribe)
61
63
 
62
64
  ## Why is it called 'mutations'?
63
65
 
@@ -82,7 +84,7 @@ And inside, you had a library of business operations that you can do against you
82
84
 
83
85
  Each of these _mutations_ takes your application from one state to the next.
84
86
 
85
- That being said, you can easily use the input validation/specification capabilities for things that don't mutate your database.
87
+ That being said, you can create commands for things that don't mutate your database.
86
88
 
87
89
  ## How do I call mutations?
88
90
 
@@ -267,5 +269,5 @@ Yes, but I don't think it's a very good idea. Better to compose.
267
269
 
268
270
  ### Can I use this with Rails forms helpers?
269
271
 
270
- Somewhat. This works great with any forms, but there's no built-in way to bake the errors into the HTML with Rails form tag helpers. Right now this is really designed to support a JSON API. You'd probably have to write an adapter of some kind.
272
+ Somewhat. Any form can submit to your server, and mutations will happily accept that input. However, if there are errors, there's no built-in way to bake the errors into the HTML with Rails form tag helpers. Right now this is really designed to support a JSON API. You'd probably have to write an adapter of some kind.
271
273
 
data/lib/mutations.rb CHANGED
@@ -20,5 +20,9 @@ module Mutations
20
20
  def error_message_creator
21
21
  @error_message_creator ||= DefaultErrorMessageCreator.new
22
22
  end
23
+
24
+ def error_message_creator=(creator)
25
+ @error_message_creator = creator
26
+ end
23
27
  end
24
28
  end
@@ -36,7 +36,10 @@ module Mutations
36
36
  )
37
37
  end
38
38
 
39
- # Key is either a symbol or a fixnum
39
+ # key: the name of the field, eg, :email. Could be nil if it's an array element
40
+ # error_symbol: the validation symbol, eg, :matches or :required
41
+ # options:
42
+ # :index -- index of error if it's in an array
40
43
  def message(key, error_symbol, options = {})
41
44
  if options[:index]
42
45
  "#{(key || 'array').to_s.titleize}[#{options[:index]}] #{MESSAGES[error_symbol]}"
@@ -1,3 +1,3 @@
1
1
  module Mutations
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
data/mutations.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.add_dependency 'activesupport'
16
16
  s.add_development_dependency 'minitest', '~> 4'
17
+ s.add_development_dependency 'rake'
17
18
 
18
19
  s.required_ruby_version = '>= 1.9.2'
19
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mutations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-25 00:00:00.000000000 Z
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '4'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: Compose your business logic into commands that sanitize and validate
47
63
  input.
48
64
  email: jnovak@gmail.com
@@ -51,8 +67,10 @@ extensions: []
51
67
  extra_rdoc_files: []
52
68
  files:
53
69
  - .gitignore
70
+ - .travis
54
71
  - Gemfile
55
72
  - Gemfile.lock
73
+ - MIT-LICENSE
56
74
  - README.md
57
75
  - Rakefile
58
76
  - lib/mutations.rb