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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29c24623a46f5019236295730d11ae4a450c5c52
4
- data.tar.gz: e3337df4d723888ef15a847f39db261cddf16794
3
+ metadata.gz: a6611e345fc3f901f3c792b604d714fb6f82f1d3
4
+ data.tar.gz: 7cc254f5ac9209bc79ac5759d1ece853b0ad786f
5
5
  SHA512:
6
- metadata.gz: 48715d52c1a4f387d5be9e0f4bec0de61089be9d67de6a3cdf8e5fbb7419d0e02eae90110d69c53f7790140d6e6b8c5b6bd8cf00bd995541349ece1bc565a19b
7
- data.tar.gz: 34e2353a1d5cffebb298b9c25988a5df03643394d207fa9ae192683b08bae248954a4f5a6f144daa2a4bbac42a22d12085e66232babfc6cfaec3d655aa668c12
6
+ metadata.gz: 16fe3329499cf11c55b16da35daf6c8385385915ebc667d3c09ca6e7ced7cefa85d0ac19ebb245f04f3e0d074c5df8e8cf527ae8f2c403da7c0052326a20d531
7
+ data.tar.gz: 269c51c15888dc90a535f015d08f720b8daf5e42ab92a6a960da3eb4847ff3366b2f017add2aa37510c4ceabf868121d4b0eecc70741c192c058cab260521c18
@@ -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
- ret = perform
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
- raise ArgumentError.new("Validations failed: #{errors.full_messages.join(',')}")
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
@@ -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
- ret << "Invalid value for param: #{key}. #{value}"
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)
@@ -14,5 +14,9 @@ module Reaction
14
14
  end
15
15
  end
16
16
 
17
+ def doc(name)
18
+ self.class.docs[name.to_sym]
19
+ end
20
+
17
21
  end
18
22
  end
@@ -15,6 +15,10 @@ module Reaction
15
15
  @metas ||= {}
16
16
  end
17
17
 
18
+ def rm_meta(name)
19
+ metas.delete(name.to_sym)
20
+ end
21
+
18
22
  def set_meta(name, meta)
19
23
  metas[name.to_sym] = meta
20
24
  end
@@ -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
@@ -4,8 +4,8 @@ module Reaction
4
4
 
5
5
  attr_reader :name
6
6
 
7
- def initialize(name)
8
- @name = name.to_sym
7
+ def initialize(name = nil)
8
+ @name = name.nil? ? nil : name.to_sym
9
9
  end
10
10
 
11
11
  # If you need to validate based on type you can. These
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.6'
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.6
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-03-11 00:00:00.000000000 Z
13
+ date: 2016-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redcarpet