reaction 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reaction/action.rb +13 -7
- data/lib/reaction/errors.rb +17 -1
- data/lib/reaction/has_attributes.rb +8 -0
- data/lib/reaction/has_docs.rb +4 -0
- data/lib/reaction/has_metas.rb +4 -0
- data/lib/reaction/has_params.rb +11 -0
- data/lib/reaction/type.rb +2 -2
- data/reaction.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6611e345fc3f901f3c792b604d714fb6f82f1d3
|
4
|
+
data.tar.gz: 7cc254f5ac9209bc79ac5759d1ece853b0ad786f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16fe3329499cf11c55b16da35daf6c8385385915ebc667d3c09ca6e7ced7cefa85d0ac19ebb245f04f3e0d074c5df8e8cf527ae8f2c403da7c0052326a20d531
|
7
|
+
data.tar.gz: 269c51c15888dc90a535f015d08f720b8daf5e42ab92a6a960da3eb4847ff3366b2f017add2aa37510c4ceabf868121d4b0eecc70741c192c058cab260521c18
|
data/lib/reaction/action.rb
CHANGED
@@ -17,28 +17,34 @@ module Reaction
|
|
17
17
|
# from being set by the request so end users can't set params
|
18
18
|
# that we don't expect them to set.
|
19
19
|
#
|
20
|
-
def initialize(params = {}, meta = {})
|
20
|
+
def initialize(params = {}, meta = {}, attributes = {})
|
21
21
|
set_params(params, meta)
|
22
|
+
set_attributes(attributes)
|
22
23
|
end
|
23
24
|
|
24
25
|
def invoke
|
25
|
-
validate
|
26
|
-
|
26
|
+
validate
|
27
|
+
return self if errors.any?
|
28
|
+
perform
|
27
29
|
ensure
|
28
30
|
cleanup
|
29
31
|
end
|
30
32
|
|
33
|
+
def self.invoke(params = {}, meta = {}, attributes = {})
|
34
|
+
new(params, meta, attributes).invoke
|
35
|
+
end
|
36
|
+
|
31
37
|
def perform
|
32
38
|
# Implement this for your action
|
33
39
|
end
|
34
40
|
|
35
|
-
def validate
|
41
|
+
def validate
|
36
42
|
errors.clear
|
37
43
|
validate_attributes
|
38
44
|
validate_params
|
39
|
-
if errors.any?
|
40
|
-
|
41
|
-
end
|
45
|
+
# if errors.any?
|
46
|
+
# raise ArgumentError.new("Validations failed: #{errors.full_messages.join(',')}")
|
47
|
+
# end
|
42
48
|
end
|
43
49
|
|
44
50
|
def cleanup
|
data/lib/reaction/errors.rb
CHANGED
@@ -28,6 +28,18 @@ module Reaction
|
|
28
28
|
messages.any?
|
29
29
|
end
|
30
30
|
|
31
|
+
def empty?
|
32
|
+
messages.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def size
|
36
|
+
messages.size
|
37
|
+
end
|
38
|
+
|
39
|
+
def length
|
40
|
+
messages.length
|
41
|
+
end
|
42
|
+
|
31
43
|
def first
|
32
44
|
messages.first
|
33
45
|
end
|
@@ -48,7 +60,11 @@ module Reaction
|
|
48
60
|
ret = []
|
49
61
|
values ||= messages[key]
|
50
62
|
values.each do |value|
|
51
|
-
|
63
|
+
if key != :base
|
64
|
+
ret << "Invalid value for param: #{key}. #{value}"
|
65
|
+
else
|
66
|
+
ret << value
|
67
|
+
end
|
52
68
|
end
|
53
69
|
ret
|
54
70
|
end
|
@@ -24,6 +24,14 @@ CODE
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def attributes
|
28
|
+
ret = {}
|
29
|
+
self.class.attributes.each do |name|
|
30
|
+
ret[name] = send(name)
|
31
|
+
end
|
32
|
+
ret
|
33
|
+
end
|
34
|
+
|
27
35
|
def set_attributes(attributes = {})
|
28
36
|
attributes.each do |key, value|
|
29
37
|
if self.class.attributes.include?(key)
|
data/lib/reaction/has_docs.rb
CHANGED
data/lib/reaction/has_metas.rb
CHANGED
data/lib/reaction/has_params.rb
CHANGED
@@ -19,6 +19,10 @@ module Reaction
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def param_provided?(name)
|
23
|
+
raw_params.has_key?(name.to_sym)
|
24
|
+
end
|
25
|
+
|
22
26
|
def param(name)
|
23
27
|
typed_params[name.to_sym] ||= begin
|
24
28
|
type = self.class.types[name.to_sym]
|
@@ -38,6 +42,13 @@ module Reaction
|
|
38
42
|
@typed_params ||= {}
|
39
43
|
end
|
40
44
|
|
45
|
+
def rm_param(name)
|
46
|
+
ret = param(name)
|
47
|
+
rm_meta(name)
|
48
|
+
raw_params.delete(name.to_sym)
|
49
|
+
ret
|
50
|
+
end
|
51
|
+
|
41
52
|
def set_param(name, value, meta = {})
|
42
53
|
return unless self.class.param_settable?(name)
|
43
54
|
set_meta(name, meta)
|
data/lib/reaction/type.rb
CHANGED
data/reaction.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = 'reaction'
|
7
|
-
gem.version = '0.2.
|
7
|
+
gem.version = '0.2.7'
|
8
8
|
gem.authors = ["Jon Calhoun", "Jon Calhoun", "Ryan Jackson"]
|
9
9
|
gem.email = ["joncalhoun@gmail.com", "jon@paidlabs.com", "ryan@paidlabs.com"]
|
10
10
|
gem.description = 'Reaction makes it easy to build reusable controller actions along with reusable validators and param type converters.'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Calhoun
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redcarpet
|