reaction 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reaction/doc.rb +6 -4
- data/lib/reaction/errors.rb +14 -3
- data/lib/reaction/has_attributes.rb +9 -0
- data/lib/reaction/has_docs.rb +1 -1
- data/lib/reaction/has_params.rb +2 -1
- data/lib/reaction/is_documented.rb +18 -0
- data/lib/reaction/markdown.rb +15 -0
- data/lib/reaction/type.rb +12 -0
- data/lib/reaction.rb +4 -0
- data/reaction.gemspec +3 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c24623a46f5019236295730d11ae4a450c5c52
|
4
|
+
data.tar.gz: e3337df4d723888ef15a847f39db261cddf16794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48715d52c1a4f387d5be9e0f4bec0de61089be9d67de6a3cdf8e5fbb7419d0e02eae90110d69c53f7790140d6e6b8c5b6bd8cf00bd995541349ece1bc565a19b
|
7
|
+
data.tar.gz: 34e2353a1d5cffebb298b9c25988a5df03643394d207fa9ae192683b08bae248954a4f5a6f144daa2a4bbac42a22d12085e66232babfc6cfaec3d655aa668c12
|
data/lib/reaction/doc.rb
CHANGED
@@ -5,13 +5,15 @@
|
|
5
5
|
#
|
6
6
|
module Reaction
|
7
7
|
class Doc
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :text, :options
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@
|
12
|
-
@message = message
|
10
|
+
def initialize(text, options = {})
|
11
|
+
@text = text
|
13
12
|
@options = options
|
14
13
|
end
|
15
14
|
|
15
|
+
def to_html(formatter = Markdown)
|
16
|
+
formatter.render(text)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
data/lib/reaction/errors.rb
CHANGED
@@ -28,6 +28,10 @@ module Reaction
|
|
28
28
|
messages.any?
|
29
29
|
end
|
30
30
|
|
31
|
+
def first
|
32
|
+
messages.first
|
33
|
+
end
|
34
|
+
|
31
35
|
def each
|
32
36
|
messages
|
33
37
|
end
|
@@ -35,9 +39,16 @@ module Reaction
|
|
35
39
|
def full_messages
|
36
40
|
ret = []
|
37
41
|
messages.each do |key, values|
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
ret |= full_messages_for(key, values)
|
43
|
+
end
|
44
|
+
ret
|
45
|
+
end
|
46
|
+
|
47
|
+
def full_messages_for(key, values = nil)
|
48
|
+
ret = []
|
49
|
+
values ||= messages[key]
|
50
|
+
values.each do |value|
|
51
|
+
ret << "Invalid value for param: #{key}. #{value}"
|
41
52
|
end
|
42
53
|
ret
|
43
54
|
end
|
@@ -7,12 +7,21 @@ module Reaction
|
|
7
7
|
module ClassMethods
|
8
8
|
def attribute(name)
|
9
9
|
attr_accessor name
|
10
|
+
eval(getter_code(name))
|
10
11
|
attributes << name
|
11
12
|
end
|
12
13
|
|
13
14
|
def attributes
|
14
15
|
@attributes ||= []
|
15
16
|
end
|
17
|
+
|
18
|
+
def getter_code(name)
|
19
|
+
<<-CODE
|
20
|
+
def #{name}
|
21
|
+
self.#{name}
|
22
|
+
end
|
23
|
+
CODE
|
24
|
+
end
|
16
25
|
end
|
17
26
|
|
18
27
|
def set_attributes(attributes = {})
|
data/lib/reaction/has_docs.rb
CHANGED
data/lib/reaction/has_params.rb
CHANGED
@@ -61,8 +61,9 @@ module Reaction
|
|
61
61
|
def validate_params
|
62
62
|
raw_params.each do |name, value|
|
63
63
|
self.class.type(name).validate_each(self, name, value)
|
64
|
+
converted = param(name)
|
64
65
|
self.class.validators(name).each do |validator|
|
65
|
-
validator.validate_each(self, name,
|
66
|
+
validator.validate_each(self, name, converted)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Reaction
|
2
|
+
module IsDocumented
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def doc(message = nil, options = {})
|
9
|
+
if message
|
10
|
+
@doc = Doc.new(message, options)
|
11
|
+
else
|
12
|
+
@doc
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Reaction
|
2
|
+
class Markdown
|
3
|
+
def self.render(md_str)
|
4
|
+
markdown.render(md_str)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.renderer
|
8
|
+
@renderer ||= Redcarpet::Render::HTML.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.markdown
|
12
|
+
@markdown ||= Redcarpet::Markdown.new(renderer, autolink: true, tables: true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/reaction/type.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Reaction
|
2
2
|
class Type
|
3
|
+
include IsDocumented
|
4
|
+
|
3
5
|
attr_reader :name
|
4
6
|
|
5
7
|
def initialize(name)
|
@@ -36,5 +38,15 @@ module Reaction
|
|
36
38
|
#
|
37
39
|
def cleanup
|
38
40
|
end
|
41
|
+
|
42
|
+
# This isn't perfect but works well enough.
|
43
|
+
def self.to_type_symbol
|
44
|
+
ret = self.to_s
|
45
|
+
ret.gsub!(/([A-Z]+)([A-Z])/, '\1_\2')
|
46
|
+
ret.gsub!(/([a-z])([A-Z])/, '\1_\2')
|
47
|
+
ret.downcase!
|
48
|
+
ret.gsub!(/_type$/, '')
|
49
|
+
ret.to_sym
|
50
|
+
end
|
39
51
|
end
|
40
52
|
end
|
data/lib/reaction.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
|
1
3
|
module Reaction
|
2
4
|
autoload :Action, 'reaction/action'
|
3
5
|
autoload :Doc, 'reaction/doc'
|
@@ -10,6 +12,8 @@ module Reaction
|
|
10
12
|
autoload :HasParams, 'reaction/has_params'
|
11
13
|
autoload :HasTypes, 'reaction/has_types'
|
12
14
|
autoload :HasValidators, 'reaction/has_validators'
|
15
|
+
autoload :IsDocumented, 'reaction/is_documented'
|
16
|
+
autoload :Markdown, 'reaction/markdown'
|
13
17
|
autoload :RawType, 'reaction/types/raw_type'
|
14
18
|
autoload :Type, 'reaction/type'
|
15
19
|
end
|
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.6'
|
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.'
|
@@ -15,4 +15,6 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency('redcarpet')
|
18
20
|
end
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Calhoun
|
@@ -10,8 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-03-
|
14
|
-
dependencies:
|
13
|
+
date: 2016-03-11 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: redcarpet
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
15
29
|
description: Reaction makes it easy to build reusable controller actions along with
|
16
30
|
reusable validators and param type converters.
|
17
31
|
email:
|
@@ -37,6 +51,8 @@ files:
|
|
37
51
|
- lib/reaction/has_params.rb
|
38
52
|
- lib/reaction/has_types.rb
|
39
53
|
- lib/reaction/has_validators.rb
|
54
|
+
- lib/reaction/is_documented.rb
|
55
|
+
- lib/reaction/markdown.rb
|
40
56
|
- lib/reaction/type.rb
|
41
57
|
- lib/reaction/types/raw_type.rb
|
42
58
|
- reaction.gemspec
|