rapid-core 0.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +35 -2
- data/Rakefile +77 -48
- data/doc/server.txt +15 -0
- data/features/settings/double-nested/default.feature +2 -2
- data/features/settings/double-nested/validates/presence_of.feature +1 -1
- data/features/settings/nested/default.feature +1 -1
- data/features/settings/nested/validates/presence_of.feature +1 -1
- data/features/settings/not_found.feature +2 -2
- data/features/step_definitions/settings_steps.rb +7 -3
- data/features/step_definitions/template_steps.rb +3 -1
- data/lib/rapid/check.rb +30 -23
- data/lib/rapid/core.rb +12 -0
- data/lib/rapid/error.rb +1 -0
- data/lib/rapid/module.rb +10 -1
- data/lib/rapid/railtie.rb +6 -0
- data/lib/rapid/setting/base.rb +31 -8
- data/lib/rapid/setting/boolean_setting.rb +20 -1
- data/lib/rapid/setting/definer.rb +11 -47
- data/lib/rapid/setting/integer_setting.rb +7 -7
- data/lib/rapid/setting/module.rb +56 -0
- data/lib/rapid/setting/namespace/base.rb +35 -60
- data/lib/rapid/setting/namespace/instance.rb +195 -28
- data/lib/rapid/setting/string_setting.rb +7 -1
- data/lib/rapid/settings.rb +51 -65
- data/lib/rapid/skeleton/base.rb +39 -18
- data/lib/rapid/skeleton/helpers/directory.rb +5 -6
- data/lib/rapid/skeleton/helpers/files.rb +62 -0
- data/lib/rapid/skeleton/helpers/gem.rb +43 -32
- data/lib/rapid/skeleton/helpers/if_setting.rb +44 -0
- data/lib/rapid/skeleton/helpers/migration.rb +102 -32
- data/lib/rapid/skeleton/helpers/route.rb +8 -12
- data/lib/rapid/skeleton/helpers/script.rb +1 -2
- data/lib/rapid/skeleton/helpers/template.rb +23 -25
- data/lib/rapid/skeleton/helpers/view.rb +7 -7
- data/lib/rapid/spec/template.rb +1 -1
- data/lib/rapid/version.rb +1 -1
- data/lib/rapid/web/base.rb +35 -0
- data/lib/rapid/web/bootstrap.rb +98 -0
- data/lib/rapid/web/controller_helpers.rb +60 -0
- data/lib/rapid/web/navigator.rb +18 -0
- data/lib/rapid/web/select_helpers.rb +63 -0
- data/lib/rapid/web/settings_form_builder.rb +205 -0
- data/lib/rapid/web/static_helpers.rb +28 -0
- data/lib/rapid/web/tasks.rb +10 -0
- data/public/rapid/core/bootstrap-collapse.js +136 -0
- data/public/rapid/core/bootstrap-responsive.min.css +3 -0
- data/public/rapid/core/bootstrap.min.css +556 -0
- data/public/rapid/core/jquery-1.7.1.js +9253 -0
- data/public/rapid/core/prettify.css +30 -0
- data/public/rapid/core/prettify.js +28 -0
- data/rapid-core.gemspec +5 -0
- data/spec/rapid/check_spec.rb +11 -4
- data/spec/rapid/module_spec.rb +18 -0
- data/spec/rapid/setting/base_spec.rb +71 -0
- data/spec/rapid/setting/boolean_setting_spec.rb +95 -0
- data/spec/rapid/setting/definer_spec.rb +7 -13
- data/spec/rapid/setting/integer_setting_spec.rb +49 -0
- data/spec/rapid/setting/module_spec.rb +25 -0
- data/spec/rapid/setting/namespace/base_spec.rb +88 -54
- data/spec/rapid/setting/namespace/instance_spec.rb +308 -5
- data/spec/rapid/setting/string_setting_spec.rb +43 -0
- data/spec/rapid/settings_spec.rb +65 -17
- data/spec/rapid/skeleton/base_spec.rb +113 -7
- data/spec/rapid/skeleton/helpers/directory_spec.rb +8 -6
- data/spec/rapid/skeleton/helpers/files_spec.rb +93 -0
- data/spec/rapid/skeleton/helpers/gem_spec.rb +65 -36
- data/spec/rapid/skeleton/helpers/if_setting_spec.rb +110 -0
- data/spec/rapid/skeleton/helpers/migration_spec.rb +190 -1
- data/spec/rapid/skeleton/helpers/route_spec.rb +13 -12
- data/spec/rapid/skeleton/helpers/script_spec.rb +2 -1
- data/spec/rapid/skeleton/helpers/template_spec.rb +22 -35
- data/spec/rapid/spec/template_spec.rb +1 -1
- data/spec/rapid/web/base_spec.rb +33 -0
- data/spec/rapid/web/bootstrap_spec.rb +72 -0
- data/spec/rapid/web/controller_helpers_spec.rb +86 -0
- data/spec/rapid/web/navigator_spec.rb +17 -0
- data/spec/rapid/web/select_helpers_spec.rb +71 -0
- data/spec/rapid/web/settings_form_builder_spec.rb +255 -0
- data/spec/rapid/web/static_helpers_spec.rb +26 -0
- data/spec/spec_helper.rb +3 -0
- data/views/index.erb +11 -0
- data/views/layout.erb +9 -0
- metadata +107 -12
- data/lib/rapid.rb +0 -37
- data/lib/rapid/setting/class_hash.rb +0 -34
- data/lib/rapid/setting/instance_hash.rb +0 -132
- data/lib/rapid/setting/instance_root.rb +0 -107
- data/spec/rapid/setting/instance_root_spec.rb +0 -161
@@ -1,107 +0,0 @@
|
|
1
|
-
module Rapid
|
2
|
-
module Setting
|
3
|
-
|
4
|
-
class InstanceRoot < InstanceHash
|
5
|
-
|
6
|
-
include ActiveModel::Validations
|
7
|
-
validate :validate_no_assignment_exceptions
|
8
|
-
validate :validate_nested_settings
|
9
|
-
|
10
|
-
attr_reader :_root
|
11
|
-
|
12
|
-
def initialize klass, owner = nil, hash = {}
|
13
|
-
@_root = owner
|
14
|
-
super klass, hash
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_binding
|
18
|
-
binding
|
19
|
-
end
|
20
|
-
|
21
|
-
def [] full_name
|
22
|
-
namespace_name, child_name = Rapid::Settings.extract_nested_namespace(full_name)
|
23
|
-
|
24
|
-
if namespace_name.nil?
|
25
|
-
super
|
26
|
-
else
|
27
|
-
namespace = @delegate[namespace_name]
|
28
|
-
namespace[child_name] if namespace
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def set? full_name
|
33
|
-
value = self[full_name]
|
34
|
-
|
35
|
-
if Setting::Namespace::Instance === value
|
36
|
-
!value.empty?
|
37
|
-
else
|
38
|
-
value != nil && value != false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def load_yaml yaml_content
|
43
|
-
hash = parse_yaml yaml_content
|
44
|
-
|
45
|
-
# yaml was empty
|
46
|
-
return true if hash == false
|
47
|
-
|
48
|
-
load_hash hash
|
49
|
-
end
|
50
|
-
|
51
|
-
def load_hash hash
|
52
|
-
hash.each do |name, value|
|
53
|
-
self[name] = value
|
54
|
-
end
|
55
|
-
|
56
|
-
true
|
57
|
-
end
|
58
|
-
|
59
|
-
def to_yaml
|
60
|
-
dot_hash = to_dot_hash
|
61
|
-
|
62
|
-
if dot_hash.empty?
|
63
|
-
""
|
64
|
-
else
|
65
|
-
Settings.clean_yaml dot_hash.to_yaml
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def to_dot_hash
|
70
|
-
Rapid::Settings.to_dot_hash to_hash
|
71
|
-
end
|
72
|
-
|
73
|
-
protected
|
74
|
-
|
75
|
-
def parse_yaml yaml_content
|
76
|
-
YAML.load yaml_content
|
77
|
-
rescue ArgumentError => e
|
78
|
-
raise Rapid::InvalidYamlError.new(e.message)
|
79
|
-
end
|
80
|
-
|
81
|
-
def validate_no_assignment_exceptions
|
82
|
-
assignment_exceptions.each do |attribute, error|
|
83
|
-
self.errors.add attribute, error.validation_message
|
84
|
-
end
|
85
|
-
|
86
|
-
true
|
87
|
-
end
|
88
|
-
|
89
|
-
def validate_nested_settings
|
90
|
-
namespaces.each do |namespace|
|
91
|
-
next if namespace.valid?
|
92
|
-
|
93
|
-
namespace.errors.each do |attribute, errors|
|
94
|
-
errors.each do |error|
|
95
|
-
self.errors.add "#{namespace.klass.name}.#{attribute}", error
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
true
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
@@ -1,161 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Rapid::Setting::InstanceRoot do
|
4
|
-
|
5
|
-
it "should expose its binding" do
|
6
|
-
@class_hash = Rapid::Setting::ClassHash.new
|
7
|
-
@instance_hash = Rapid::Setting::InstanceRoot.new @class_hash
|
8
|
-
|
9
|
-
@instance_hash.get_binding.should_not be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "namespaces" do
|
13
|
-
|
14
|
-
before do
|
15
|
-
@class_hash = Rapid::Setting::ClassHash.new
|
16
|
-
@app = Rapid::Setting::Namespace::Base.new(:app)
|
17
|
-
@name = Rapid::Setting::StringSetting.new(:name, :namespace => @app)
|
18
|
-
|
19
|
-
@class_hash[:app] = @app
|
20
|
-
@app[:name] = @name
|
21
|
-
|
22
|
-
@instance_hash = Rapid::Setting::InstanceRoot.new @class_hash
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should load the namespaces from nested hashes" do
|
26
|
-
@instance_hash.load_hash :app => {:name => "Rapid"}
|
27
|
-
@instance_hash[:app][:name].should == "Rapid"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should load the namespaces using dot-notation" do
|
31
|
-
@instance_hash.load_hash 'app.name' => "Rapid"
|
32
|
-
@instance_hash[:app][:name].should == "Rapid"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should output the yaml in dot-notation" do
|
36
|
-
@instance_hash.load_hash 'app.name' => "Rapid"
|
37
|
-
@instance_hash.to_yaml.should == %(app.name: Rapid)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should provide [] access to nested settings" do
|
41
|
-
@instance_hash.load_hash 'app.name' => "Rapid"
|
42
|
-
@instance_hash['app.name'].should == "Rapid"
|
43
|
-
|
44
|
-
@instance_hash['app.invalid'].should == nil
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "two-deep namespaces" do
|
50
|
-
|
51
|
-
before do
|
52
|
-
@class_hash = Rapid::Setting::ClassHash.new
|
53
|
-
@app = Rapid::Setting::Namespace::Base.new(:app)
|
54
|
-
@author = Rapid::Setting::Namespace::Base.new(:author)
|
55
|
-
@name = Rapid::Setting::StringSetting.new(:name, :namespace => @autor)
|
56
|
-
|
57
|
-
@class_hash[:app] = @app
|
58
|
-
@app[:author] = @author
|
59
|
-
@author[:name] = @name
|
60
|
-
|
61
|
-
@instance_hash = Rapid::Setting::InstanceRoot.new @class_hash
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should load the namespaces from nested hashes" do
|
65
|
-
@instance_hash.load_hash :app => {:author => {:name => "Dan"} }
|
66
|
-
@instance_hash[:app][:author][:name].should == "Dan"
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should load the namespaces using dot-notation" do
|
70
|
-
@instance_hash.load_hash 'app.author.name' => "Dan"
|
71
|
-
@instance_hash[:app][:author][:name].should == "Dan"
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should output the yaml in dot-notation" do
|
75
|
-
@instance_hash.load_hash 'app.author.name' => "Dan"
|
76
|
-
@instance_hash.to_yaml.should == %(app.author.name: Dan)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should provide [] access" do
|
80
|
-
@instance_hash.load_hash 'app.author.name' => "Dan"
|
81
|
-
@instance_hash['app.author.name'].should == "Dan"
|
82
|
-
|
83
|
-
@instance_hash['app.author.invalid'].should == nil
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should know set?" do
|
87
|
-
@instance_hash.set?('app').should == false
|
88
|
-
@instance_hash.set?('app.author').should == false
|
89
|
-
@instance_hash.set?('app.author.name').should == false
|
90
|
-
@instance_hash.set?('app.author.invalid').should == false
|
91
|
-
|
92
|
-
@instance_hash.load_hash 'app.author.name' => "Dan"
|
93
|
-
|
94
|
-
@instance_hash.set?('app').should == true
|
95
|
-
@instance_hash.set?('app.author').should == true
|
96
|
-
@instance_hash.set?('app.author.name').should == true
|
97
|
-
@instance_hash.set?('app.author.invalid').should == false
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "YAML" do
|
103
|
-
|
104
|
-
before do
|
105
|
-
@class_hash = Rapid::Setting::ClassHash.new
|
106
|
-
@class_hash[:name] = Rapid::Setting::StringSetting.new(:name)
|
107
|
-
@class_hash[:version] = Rapid::Setting::StringSetting.new(:version)
|
108
|
-
|
109
|
-
@instance_hash = Rapid::Setting::InstanceRoot.new @class_hash
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "loading" do
|
113
|
-
|
114
|
-
def load_yaml content
|
115
|
-
@instance_hash.load_yaml content
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should load the hash with values" do
|
119
|
-
load_yaml %(name: Dan)
|
120
|
-
@instance_hash["name"].should == "Dan"
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should handle empty files" do
|
124
|
-
load_yaml %()
|
125
|
-
@instance_hash.empty?.should be_true
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should raise an error when an unknown setting is specified" do
|
129
|
-
load_yaml %(foo: bar)
|
130
|
-
@instance_hash.valid?.should be_false
|
131
|
-
@instance_hash.errors["foo"].should == ["can't be found"]
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should raise error when yaml is invalid" do
|
135
|
-
lambda { load_yaml %(foo: d\nea5#) }.should raise_error(Rapid::InvalidYamlError)
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "to_yaml" do
|
141
|
-
|
142
|
-
def to_yaml
|
143
|
-
@instance_hash.to_yaml
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should write current settings" do
|
147
|
-
@instance_hash["name"] = "Dan"
|
148
|
-
@instance_hash["version"] = "1.0"
|
149
|
-
|
150
|
-
to_yaml.should == %(name: Dan\nversion: "1.0")
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should handle empty settings" do
|
154
|
-
to_yaml.should == %()
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
end
|