rapid-core 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +53 -0
- data/Rakefile +61 -0
- data/cucumber.yml +3 -0
- data/doc/plan.txt +89 -0
- data/doc/scaffold/controller.rb +83 -0
- data/doc/scaffold/helper.rb +2 -0
- data/doc/scaffold/model.rb +5 -0
- data/doc/scaffold/rapid_scaffold.rb +5 -0
- data/doc/scaffold/views/_form.html.erb +25 -0
- data/doc/scaffold/views/edit.html.erb +6 -0
- data/doc/scaffold/views/index.html.erb +25 -0
- data/doc/scaffold/views/new.html.erb +5 -0
- data/doc/scaffold/views/show.html.erb +15 -0
- data/features/settings/boolean/default.feature +36 -0
- data/features/settings/double-nested/default.feature +50 -0
- data/features/settings/double-nested/if.feature +41 -0
- data/features/settings/double-nested/unless.feature +39 -0
- data/features/settings/double-nested/validates/exclusion_of.feature +30 -0
- data/features/settings/double-nested/validates/format_of.feature +30 -0
- data/features/settings/double-nested/validates/inclusion_of.feature +30 -0
- data/features/settings/double-nested/validates/length_of.feature +30 -0
- data/features/settings/double-nested/validates/presence_of.feature +37 -0
- data/features/settings/double-nested/validates/size_of.feature +30 -0
- data/features/settings/integer/default.feature +49 -0
- data/features/settings/nested/default.feature +50 -0
- data/features/settings/nested/if.feature +53 -0
- data/features/settings/nested/unless.feature +32 -0
- data/features/settings/nested/validates/exclusion_of.feature +30 -0
- data/features/settings/nested/validates/format_of.feature +30 -0
- data/features/settings/nested/validates/inclusion_of.feature +30 -0
- data/features/settings/nested/validates/length_of.feature +30 -0
- data/features/settings/nested/validates/presence_of.feature +37 -0
- data/features/settings/nested/validates/size_of.feature +30 -0
- data/features/settings/not_found.feature +33 -0
- data/features/settings/string/default.feature +36 -0
- data/features/settings/string/validates/exclusion_of.feature +30 -0
- data/features/settings/string/validates/format_of.feature +30 -0
- data/features/settings/string/validates/inclusion_of.feature +30 -0
- data/features/settings/string/validates/length_of.feature +30 -0
- data/features/settings/string/validates/presence_of.feature +37 -0
- data/features/settings/string/validates/size_of.feature +30 -0
- data/features/step_definitions/settings_steps.rb +92 -0
- data/features/step_definitions/skeleton_steps.rb +68 -0
- data/features/step_definitions/template_steps.rb +39 -0
- data/features/support/env.rb +6 -0
- data/features/templates/comment_if.feature +55 -0
- data/features/templates/comment_unless.feature +56 -0
- data/features/templates/for/for.feature +51 -0
- data/features/templates/if/else.feature +60 -0
- data/features/templates/if/elsif.feature +82 -0
- data/features/templates/if/if.feature +55 -0
- data/features/templates/namespaces/exist.feature +54 -0
- data/features/templates/static.feature +37 -0
- data/features/templates/variables.feature +61 -0
- data/lib/rapid/check.rb +162 -0
- data/lib/rapid/core.rb +37 -0
- data/lib/rapid/error.rb +84 -0
- data/lib/rapid/module.rb +35 -0
- data/lib/rapid/railtie.rb +18 -0
- data/lib/rapid/setting/base.rb +35 -0
- data/lib/rapid/setting/boolean_setting.rb +17 -0
- data/lib/rapid/setting/class_hash.rb +34 -0
- data/lib/rapid/setting/comments.rb +25 -0
- data/lib/rapid/setting/definer.rb +151 -0
- data/lib/rapid/setting/instance_hash.rb +132 -0
- data/lib/rapid/setting/instance_root.rb +107 -0
- data/lib/rapid/setting/integer_setting.rb +24 -0
- data/lib/rapid/setting/namespace/base.rb +113 -0
- data/lib/rapid/setting/namespace/instance.rb +84 -0
- data/lib/rapid/setting/nested_validations.rb +86 -0
- data/lib/rapid/setting/string_setting.rb +13 -0
- data/lib/rapid/settings.rb +129 -0
- data/lib/rapid/skeleton/base.rb +164 -0
- data/lib/rapid/skeleton/helpers/directory.rb +53 -0
- data/lib/rapid/skeleton/helpers/gem.rb +133 -0
- data/lib/rapid/skeleton/helpers/migration.rb +46 -0
- data/lib/rapid/skeleton/helpers/route.rb +115 -0
- data/lib/rapid/skeleton/helpers/script.rb +33 -0
- data/lib/rapid/skeleton/helpers/template.rb +73 -0
- data/lib/rapid/skeleton/helpers/view.rb +35 -0
- data/lib/rapid/spec/template.rb +104 -0
- data/lib/rapid/spec.rb +1 -0
- data/lib/rapid/tasks.rb +29 -0
- data/lib/rapid/template/base.rb +49 -0
- data/lib/rapid/template/node/base.rb +43 -0
- data/lib/rapid/template/node/comment_node.rb +42 -0
- data/lib/rapid/template/node/if_node.rb +109 -0
- data/lib/rapid/template/node/root.rb +51 -0
- data/lib/rapid/template/node/static.rb +29 -0
- data/lib/rapid/template/node/variable.rb +86 -0
- data/lib/rapid/template/parser.rb +167 -0
- data/lib/rapid/template/pulling/base.rb +91 -0
- data/lib/rapid/template/pulling/explicit.rb +92 -0
- data/lib/rapid/template/pulling/forgiving.rb +58 -0
- data/lib/rapid/version.rb +3 -0
- data/lib/rapid.rb +37 -0
- data/rapid-core.gemspec +26 -0
- data/spec/rapid/check_spec.rb +119 -0
- data/spec/rapid/error_spec.rb +14 -0
- data/spec/rapid/module_spec.rb +28 -0
- data/spec/rapid/setting/base_spec.rb +17 -0
- data/spec/rapid/setting/definer_spec.rb +318 -0
- data/spec/rapid/setting/instance_root_spec.rb +161 -0
- data/spec/rapid/setting/namespace/base_spec.rb +93 -0
- data/spec/rapid/setting/namespace/instance_spec.rb +12 -0
- data/spec/rapid/setting/nested_validations_spec.rb +72 -0
- data/spec/rapid/settings_spec.rb +51 -0
- data/spec/rapid/skeleton/base_spec.rb +224 -0
- data/spec/rapid/skeleton/helpers/directory_spec.rb +104 -0
- data/spec/rapid/skeleton/helpers/gem_spec.rb +180 -0
- data/spec/rapid/skeleton/helpers/migration_spec.rb +23 -0
- data/spec/rapid/skeleton/helpers/route_spec.rb +120 -0
- data/spec/rapid/skeleton/helpers/script_spec.rb +57 -0
- data/spec/rapid/skeleton/helpers/template_spec.rb +142 -0
- data/spec/rapid/skeleton/helpers/view_spec.rb +54 -0
- data/spec/rapid/spec/template_spec.rb +168 -0
- data/spec/rapid/template/base_spec.rb +290 -0
- data/spec/rapid/template/node/base_spec.rb +9 -0
- data/spec/rapid/template/node/comment_node_spec.rb +46 -0
- data/spec/rapid/template/node/if_node_spec.rb +28 -0
- data/spec/rapid/template/node/root_spec.rb +9 -0
- data/spec/rapid/template/node/static_spec.rb +17 -0
- data/spec/rapid/template/node/variable_spec.rb +87 -0
- data/spec/rapid/template/parser_spec.rb +187 -0
- data/spec/rapid/template/pulling/base_spec.rb +81 -0
- data/spec/rapid/template/pulling/explicit_spec.rb +33 -0
- data/spec/rapid/template/pulling/forgiving_spec.rb +132 -0
- data/spec/spec_helper.rb +10 -0
- metadata +325 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
module Rapid
|
2
|
+
module Template
|
3
|
+
|
4
|
+
class Parser
|
5
|
+
|
6
|
+
def initialize content
|
7
|
+
@content = content.clone
|
8
|
+
@is_first = true
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
Engine.new(@content).root
|
13
|
+
end
|
14
|
+
|
15
|
+
class Engine < Erubis::Basic::Engine
|
16
|
+
|
17
|
+
def initialize *args
|
18
|
+
@nodes = []
|
19
|
+
@stack = [@nodes]
|
20
|
+
super *args
|
21
|
+
end
|
22
|
+
|
23
|
+
def root
|
24
|
+
Template::Node::Root.new @nodes
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def add_preamble buf
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_postamble buf
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_text buf, text
|
38
|
+
push_node Node::Static.new(text) unless text.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_expr buf, e, indicator
|
42
|
+
case indicator
|
43
|
+
when "="
|
44
|
+
push_variable e.strip
|
45
|
+
else
|
46
|
+
raise UnknownMethodTemplateError.new("unknown method #{indicator} #{e}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_stmt buf, code
|
51
|
+
code.strip!
|
52
|
+
|
53
|
+
if code == "end"
|
54
|
+
pop_node
|
55
|
+
|
56
|
+
elsif code =~ /^if /
|
57
|
+
push_if $'
|
58
|
+
|
59
|
+
elsif code =~ /^elsif /
|
60
|
+
push_elsif $'
|
61
|
+
|
62
|
+
|
63
|
+
elsif code =~ /^else/
|
64
|
+
push_else
|
65
|
+
|
66
|
+
elsif code.empty?
|
67
|
+
# do nothing
|
68
|
+
|
69
|
+
else
|
70
|
+
raise UnknownMethodTemplateError.new("unknown method #{code.inspect}")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def push_node node
|
75
|
+
array = nil
|
76
|
+
|
77
|
+
current = @stack.last
|
78
|
+
if current.is_a? Array
|
79
|
+
array = current
|
80
|
+
|
81
|
+
elsif current.is_a? Hash
|
82
|
+
case current[:type]
|
83
|
+
when :if
|
84
|
+
|
85
|
+
if current[:else] != nil
|
86
|
+
array = current[:else]
|
87
|
+
elsif current[:elsif].last
|
88
|
+
array = current[:elsif].last[:then]
|
89
|
+
else
|
90
|
+
array = current[:then]
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if node.is_a?(Node::Static) && array.last.is_a?(Node::Static)
|
97
|
+
prev = array.pop
|
98
|
+
node = Node::Static.new(prev.content + node.content)
|
99
|
+
end
|
100
|
+
|
101
|
+
array.push node
|
102
|
+
end
|
103
|
+
|
104
|
+
def push_variable code
|
105
|
+
if code =~ /^comment_unless /
|
106
|
+
node = Node::CommentNode.new(false, $')
|
107
|
+
elsif code =~ /^comment_if /
|
108
|
+
node = Node::CommentNode.new(true, $')
|
109
|
+
else
|
110
|
+
node = Node::Variable.new(code)
|
111
|
+
end
|
112
|
+
|
113
|
+
push_node node
|
114
|
+
end
|
115
|
+
|
116
|
+
def pop_node
|
117
|
+
node = build_node @stack.pop
|
118
|
+
push_node node
|
119
|
+
end
|
120
|
+
|
121
|
+
def build_node node
|
122
|
+
case node[:type]
|
123
|
+
when :if
|
124
|
+
build_if_node node
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def build_if_node node
|
129
|
+
else_node = node[:else]
|
130
|
+
|
131
|
+
node[:elsif].reverse_each do |n|
|
132
|
+
else_node = Node::IfNode.new n[:statement], n[:then], else_node
|
133
|
+
end
|
134
|
+
|
135
|
+
Node::IfNode.new node[:statement], node[:then], else_node
|
136
|
+
end
|
137
|
+
|
138
|
+
def push_if statement
|
139
|
+
@stack.push :type => :if, :statement => statement, :then => [], :elsif => []
|
140
|
+
end
|
141
|
+
|
142
|
+
def push_elsif statement
|
143
|
+
if_node = self.current_if
|
144
|
+
if_node[:elsif].push :statement => statement, :then => []
|
145
|
+
end
|
146
|
+
|
147
|
+
def push_else
|
148
|
+
if_node = self.current_if
|
149
|
+
if_node[:else] ||= [] if if_node
|
150
|
+
end
|
151
|
+
|
152
|
+
def current_if
|
153
|
+
if_node = nil
|
154
|
+
@stack.reverse_each do |d|
|
155
|
+
if d.is_a?(Hash) && d[:type] == :if
|
156
|
+
if_node ||= d
|
157
|
+
end
|
158
|
+
end
|
159
|
+
if_node
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Rapid
|
2
|
+
module Template
|
3
|
+
module Pulling
|
4
|
+
|
5
|
+
class Base
|
6
|
+
|
7
|
+
attr_reader :result, :previous_content
|
8
|
+
|
9
|
+
delegate :[], :to => :result
|
10
|
+
delegate :[]=, :to => :result
|
11
|
+
|
12
|
+
def initialize content
|
13
|
+
@result = {}
|
14
|
+
@previous_content = ""
|
15
|
+
end
|
16
|
+
|
17
|
+
def key? key
|
18
|
+
@result.key? key
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
remove_covered_namespaces!
|
23
|
+
@result
|
24
|
+
end
|
25
|
+
|
26
|
+
def raise_not_matching content
|
27
|
+
raise Rapid::NotMatchingTemplateError.new(result, content, self.content, :previous => previous_content)
|
28
|
+
end
|
29
|
+
|
30
|
+
def content
|
31
|
+
raise NotImplementedError.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def index content
|
35
|
+
raise NotImplementedError.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def starts_with? content
|
39
|
+
raise NotImplementedError.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def starts_with content
|
43
|
+
raise NotImplementedError.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def move! count
|
47
|
+
raise NotImplementedError.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def match content
|
51
|
+
raise NotImplementedError.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def match! content
|
55
|
+
raise NotImplementedError.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def empty!
|
59
|
+
raise NotImplementedError.new
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
# remove results that cover other nested results:
|
65
|
+
# {"app.author"=>true, "app.author.name"=>"Dan"}
|
66
|
+
# would remove app.author
|
67
|
+
def remove_covered_namespaces!
|
68
|
+
# TODO clean up
|
69
|
+
|
70
|
+
remove = []
|
71
|
+
@result.keys.each do |key|
|
72
|
+
is_covering = false
|
73
|
+
start = "#{key}."
|
74
|
+
|
75
|
+
covered_keys = @result.keys.each do |k|
|
76
|
+
is_covering = is_covering || k.starts_with?(start)
|
77
|
+
end
|
78
|
+
|
79
|
+
remove.push key if is_covering
|
80
|
+
end
|
81
|
+
|
82
|
+
remove.each do |key|
|
83
|
+
@result.delete key
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Rapid
|
2
|
+
module Template
|
3
|
+
module Pulling
|
4
|
+
|
5
|
+
class Explicit < Base
|
6
|
+
|
7
|
+
attr_reader :content, :previous_content
|
8
|
+
|
9
|
+
def initialize content
|
10
|
+
super
|
11
|
+
@content = content.clone
|
12
|
+
@previous_content = ""
|
13
|
+
end
|
14
|
+
|
15
|
+
def index content
|
16
|
+
@content.index content
|
17
|
+
end
|
18
|
+
|
19
|
+
def starts_with? content
|
20
|
+
@content.starts_with? content
|
21
|
+
end
|
22
|
+
|
23
|
+
def starts_with content
|
24
|
+
content.length if @content.starts_with? content
|
25
|
+
end
|
26
|
+
|
27
|
+
def move! count
|
28
|
+
return 0 if count == 0
|
29
|
+
|
30
|
+
matched = @content.slice!(0..count-1)
|
31
|
+
@previous_content << matched
|
32
|
+
@previous_content = @previous_content[@previous_content.length - 50..-1] if @previous_content.length > 50
|
33
|
+
count
|
34
|
+
end
|
35
|
+
|
36
|
+
def match content
|
37
|
+
internal_match @content, content
|
38
|
+
end
|
39
|
+
|
40
|
+
def match! content
|
41
|
+
result, a, b = match content
|
42
|
+
unless result
|
43
|
+
raise_not_matching content
|
44
|
+
end
|
45
|
+
|
46
|
+
move! a
|
47
|
+
end
|
48
|
+
|
49
|
+
def empty!
|
50
|
+
unless @content.nil? || @content.empty?
|
51
|
+
raise_not_matching ""
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def raise_not_matching content
|
56
|
+
failure, a_count, b_count = internal_match_miss @content, content
|
57
|
+
|
58
|
+
if a_count > 0
|
59
|
+
move! a_count
|
60
|
+
end
|
61
|
+
|
62
|
+
if b_count > 0
|
63
|
+
content = content[b_count..-1]
|
64
|
+
end
|
65
|
+
|
66
|
+
raise Rapid::NotMatchingTemplateError.new(result, content, @content, :previous => @previous_content)
|
67
|
+
end
|
68
|
+
|
69
|
+
protected
|
70
|
+
|
71
|
+
def internal_match a, b
|
72
|
+
if a.starts_with? b
|
73
|
+
return true, b.length, b.length
|
74
|
+
else
|
75
|
+
internal_match_miss a, b
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def internal_match_miss a, b
|
80
|
+
count = 0
|
81
|
+
while a.length > count && b.length > count && a[count] == b[count]
|
82
|
+
count += 1
|
83
|
+
end
|
84
|
+
|
85
|
+
return false, count, count
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Rapid
|
2
|
+
module Template
|
3
|
+
module Pulling
|
4
|
+
|
5
|
+
class Forgiving < Explicit
|
6
|
+
|
7
|
+
def match content
|
8
|
+
result, a, b = super content
|
9
|
+
return result, a, b if result
|
10
|
+
|
11
|
+
if @content =~ starts_with_newline_regex
|
12
|
+
len = $1.length
|
13
|
+
result, a, b = internal_match $', content
|
14
|
+
a += len
|
15
|
+
return result, a, b
|
16
|
+
|
17
|
+
elsif content =~ starts_with_newline_regex
|
18
|
+
len = $1.length
|
19
|
+
result, a, b = internal_match @content, $'
|
20
|
+
b += len
|
21
|
+
return result, a, b
|
22
|
+
|
23
|
+
else
|
24
|
+
return result, a, b
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def starts_with_newline_regex
|
31
|
+
/\A([\ ]*[\n]+)/
|
32
|
+
end
|
33
|
+
|
34
|
+
def internal_match_miss a, b
|
35
|
+
a_count = 0
|
36
|
+
b_count = 0
|
37
|
+
|
38
|
+
if a =~ starts_with_newline_regex
|
39
|
+
a_count += $1.length
|
40
|
+
end
|
41
|
+
|
42
|
+
if b =~ starts_with_newline_regex
|
43
|
+
b_count += $1.length
|
44
|
+
end
|
45
|
+
|
46
|
+
while a.length > a_count && b.length > b_count && a[a_count] == b[b_count]
|
47
|
+
a_count += 1
|
48
|
+
b_count += 1
|
49
|
+
end
|
50
|
+
|
51
|
+
return false, a_count, b_count
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/rapid.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erubis'
|
3
|
+
require 'active_support/core_ext/string'
|
4
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
|
+
require 'active_model'
|
6
|
+
|
7
|
+
require "rapid/version"
|
8
|
+
require "rapid/error"
|
9
|
+
require "rapid/module"
|
10
|
+
|
11
|
+
require "rapid/settings"
|
12
|
+
require "rapid/check"
|
13
|
+
|
14
|
+
require "rapid/skeleton/helpers/directory"
|
15
|
+
require "rapid/skeleton/helpers/gem"
|
16
|
+
require "rapid/skeleton/helpers/migration"
|
17
|
+
require "rapid/skeleton/helpers/route"
|
18
|
+
require "rapid/skeleton/helpers/script"
|
19
|
+
require "rapid/skeleton/helpers/template"
|
20
|
+
require "rapid/skeleton/helpers/view"
|
21
|
+
require "rapid/skeleton/base"
|
22
|
+
|
23
|
+
require "rapid/template/base"
|
24
|
+
require "rapid/template/parser"
|
25
|
+
|
26
|
+
require "rapid/template/pulling/base"
|
27
|
+
require "rapid/template/pulling/explicit"
|
28
|
+
require "rapid/template/pulling/forgiving"
|
29
|
+
|
30
|
+
require "rapid/template/node/base"
|
31
|
+
require "rapid/template/node/root"
|
32
|
+
require "rapid/template/node/static"
|
33
|
+
require "rapid/template/node/variable"
|
34
|
+
require "rapid/template/node/if_node"
|
35
|
+
require "rapid/template/node/comment_node"
|
36
|
+
|
37
|
+
require 'rapid/railtie' if defined? Rails
|
data/rapid-core.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rapid/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rapid-core"
|
7
|
+
s.version = Rapid::VERSION
|
8
|
+
s.authors = ["Dan Cunning"]
|
9
|
+
s.email = ["dancunning@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Code that understands code and can change it programmatically}
|
12
|
+
s.description = %q{Code that understands code and can change it programmatically}
|
13
|
+
|
14
|
+
s.rubyforge_project = "rapid-core"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_dependency("activesupport", ">= 3.0")
|
23
|
+
s.add_dependency("activemodel", ">= 3.0")
|
24
|
+
s.add_dependency("i18n")
|
25
|
+
s.add_dependency("erubis")
|
26
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Rapid::Check do
|
4
|
+
|
5
|
+
after do
|
6
|
+
Rapid::Check.instance_variable_set :@current, nil
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "new_with_detection" do
|
10
|
+
|
11
|
+
after do
|
12
|
+
FileUtils.rm_rf('rapid.rb')
|
13
|
+
FileUtils.rm_rf('foo.rb')
|
14
|
+
Rapid::Check.file = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise an error when nothing is setup" do
|
18
|
+
lambda { Rapid::Check.new_with_detection }.should raise_error(Rapid::FileNotFoundCheckError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be Rapid::Check.file if it's set" do
|
22
|
+
File.open('foo.rb', 'w') {|f| f.write('hi') }
|
23
|
+
Rapid::Check.file = 'foo.rb'
|
24
|
+
Rapid::Check.new_with_detection.code.should == 'hi'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be one of the custom files if it exists" do
|
28
|
+
File.open('rapid.rb', 'w') {|f| f.write('hi') }
|
29
|
+
Rapid::Check.new_with_detection.code.should == 'hi'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "valid?" do
|
35
|
+
|
36
|
+
after do
|
37
|
+
FileUtils.rm_rf('rapid.rb')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should allow the code to add errors" do
|
41
|
+
@check = Rapid::Check.new "Rapid::Check.current.error 'config.rb', 'is missing'"
|
42
|
+
@check.valid?.should == false
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not let Rapid::Check.current linger" do
|
46
|
+
@check = Rapid::Check.new ""
|
47
|
+
@check.valid?.should == true
|
48
|
+
Rapid::Check.current.should == nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not catch problems in the code" do
|
52
|
+
@check = Rapid::Check.new "foo"
|
53
|
+
lambda { @check.valid? }.should raise_error(NameError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should output to the console if asked" do
|
57
|
+
@check = Rapid::Check.new %(
|
58
|
+
Rapid::Check.current.ok 'config.rb', 'is great!'
|
59
|
+
Rapid::Check.current.warning 'config.rb', 'is missing'
|
60
|
+
Rapid::Check.current.error 'config.rb', 'is broken!'
|
61
|
+
), :console => true
|
62
|
+
|
63
|
+
Rapid.should_receive(:color_puts).exactly(5).times
|
64
|
+
@check.valid?.should == false
|
65
|
+
@check.check_count.should == 3
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should accept exceptions" do
|
69
|
+
Rapid.should_receive(:color_puts).exactly(9).times
|
70
|
+
|
71
|
+
@exception = Rapid::NotMatchingTemplateError.new({"foo" => "bar" * 40, 4 => "foo"}, "", "bar")
|
72
|
+
@check = Rapid::Check.new "", :console => true
|
73
|
+
@check.exception "my.rb", @exception
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should output with indention" do
|
77
|
+
@check = Rapid::Check.new %(
|
78
|
+
Rapid::Check.current.with_section("app") do
|
79
|
+
Rapid::Check.current.ok 'config.rb', 'is great!'
|
80
|
+
end
|
81
|
+
), :console => true
|
82
|
+
|
83
|
+
@check.should_receive(:puts).with("")
|
84
|
+
@check.should_receive(:puts).with("app")
|
85
|
+
Rapid.should_receive(:color_puts).with(:ok, " config.rb is great!")
|
86
|
+
@check.valid?.should == true
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should track the amount of calls" do
|
90
|
+
@check = Rapid::Check.new %(
|
91
|
+
Rapid::Check.current.ok 'config.rb', 'is great!'
|
92
|
+
Rapid::Check.current.ok 'config.rb', 'is great!'
|
93
|
+
Rapid::Check.current.ok 'config.rb', 'is great!'
|
94
|
+
|
95
|
+
Rapid::Check.current.warning 'config.rb', 'is missing'
|
96
|
+
Rapid::Check.current.warning 'config.rb', 'is missing'
|
97
|
+
|
98
|
+
Rapid::Check.current.error 'config.rb', 'is broken!'
|
99
|
+
)
|
100
|
+
|
101
|
+
@check.valid?.should == false
|
102
|
+
@check.ok_count.should == 3
|
103
|
+
@check.warning_count.should == 2
|
104
|
+
@check.error_count.should == 1
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should tell whether encounters an error" do
|
110
|
+
@check = Rapid::Check.new ""
|
111
|
+
Rapid::Check.current = @check
|
112
|
+
Rapid::Check.encounters_error? { @check.error 'hi', 'hi' }.should == true
|
113
|
+
|
114
|
+
@check = Rapid::Check.new ""
|
115
|
+
Rapid::Check.current = @check
|
116
|
+
Rapid::Check.encounters_error? { @check.warning 'hi', 'hi' }.should == false
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Rapid::Exception do
|
4
|
+
|
5
|
+
describe "NotMatchingTemplateError" do
|
6
|
+
|
7
|
+
it "should have a message" do
|
8
|
+
@error = Rapid::NotMatchingTemplateError.new({}, "", "")
|
9
|
+
@error.message.class.should == String
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Rapid do
|
4
|
+
|
5
|
+
describe "puts" do
|
6
|
+
|
7
|
+
it "should puts ok" do
|
8
|
+
Rapid.should_receive(:puts).with("\e[32mhi\e[0m")
|
9
|
+
Rapid.color_puts :ok, "hi"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should puts warning" do
|
13
|
+
Rapid.should_receive(:puts).with("\e[33mhi\e[0m")
|
14
|
+
Rapid.color_puts :warning, "hi"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should puts error" do
|
18
|
+
Rapid.should_receive(:puts).with("\e[31mhi\e[0m")
|
19
|
+
Rapid.color_puts :error, "hi"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise an error when invalid type" do
|
23
|
+
lambda { Rapid.color_puts(:invalid, "hi") }.should raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Rapid::Setting::Base do
|
4
|
+
|
5
|
+
it "should throw an error when loading" do
|
6
|
+
lambda { Rapid::Setting::Base.new("foo").load("hi") }.should raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not allow settings named _root" do
|
10
|
+
lambda { Rapid::Setting::Base.new("_root") }.should raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not allow settings named valid" do
|
14
|
+
lambda { Rapid::Setting::Base.new("valid") }.should raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|