impromptu 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +34 -0
- data/README.rdoc +76 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/impromptu.gemspec +106 -0
- data/lib/impromptu/autoload.rb +33 -0
- data/lib/impromptu/component.rb +124 -0
- data/lib/impromptu/component_set.rb +10 -0
- data/lib/impromptu/file.rb +220 -0
- data/lib/impromptu/folder.rb +151 -0
- data/lib/impromptu/impromptu.rb +81 -0
- data/lib/impromptu/ordered_set.rb +49 -0
- data/lib/impromptu/resource.rb +195 -0
- data/lib/impromptu/symbol.rb +43 -0
- data/lib/impromptu.rb +12 -0
- data/test/framework/copies/extra_klass2.rb +7 -0
- data/test/framework/copies/new_klass.rb +10 -0
- data/test/framework/copies/new_unseen.rb +7 -0
- data/test/framework/copies/original_klass.rb +10 -0
- data/test/framework/ext/extensions/blog.rb +6 -0
- data/test/framework/ext/extensions.rb +4 -0
- data/test/framework/lib/group/klass2.rb +4 -0
- data/test/framework/lib/klass.rb +10 -0
- data/test/framework/other/also.rb +8 -0
- data/test/framework/other/ignore.rb +2 -0
- data/test/framework/other/load.rb +2 -0
- data/test/framework/other/two.rb +14 -0
- data/test/framework/private/klass.rb +10 -0
- data/test/framework/test.components +23 -0
- data/test/helper.rb +10 -0
- data/test/test_autoload.rb +32 -0
- data/test/test_component.rb +133 -0
- data/test/test_component_set.rb +20 -0
- data/test/test_folder.rb +4 -0
- data/test/test_impromptu.rb +43 -0
- data/test/test_integration.rb +312 -0
- data/test/test_ordered_set.rb +93 -0
- data/test/test_resource.rb +186 -0
- data/test/test_symbol.rb +99 -0
- metadata +139 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
# Extensions to all Symbols to make it easier to deal
|
2
|
+
# with namespaced, nested symbol names
|
3
|
+
class Symbol
|
4
|
+
# True if this symbol contains namespaces (is a nested
|
5
|
+
# symbol such as A::B).
|
6
|
+
def nested?
|
7
|
+
self.to_s.include? '::'
|
8
|
+
end
|
9
|
+
|
10
|
+
# True if this symbol contains no namespaces (is a root
|
11
|
+
# symbol such as A, in contrast to to A::B).
|
12
|
+
def unnested?
|
13
|
+
!self.nested?
|
14
|
+
end
|
15
|
+
|
16
|
+
# Split a symbol into its component names (A::B =>
|
17
|
+
# [:A, :B])
|
18
|
+
def nested_symbols
|
19
|
+
self.to_s.split('::').collect(&:to_sym)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Retrieve the base (end or final) symbol name from this
|
23
|
+
# symbol (the Class or Module actually being referred to).
|
24
|
+
def base_symbol
|
25
|
+
self.nested_symbols.last
|
26
|
+
end
|
27
|
+
|
28
|
+
# Retrieve the root (first) symbol name from this symbol.
|
29
|
+
def root_symbol
|
30
|
+
self.nested_symbols.first
|
31
|
+
end
|
32
|
+
|
33
|
+
# Iterate through a namespaced symbol by visiting each
|
34
|
+
# name in turn, including its parent names. e.g calling
|
35
|
+
# on A::B::C would yield :A, :A::B, and :A::B::C
|
36
|
+
def each_namespaced_symbol
|
37
|
+
self.nested_symbols.inject([]) do |name, symbol|
|
38
|
+
name << symbol
|
39
|
+
yield name.join('::').to_sym
|
40
|
+
name
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/impromptu.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
require 'impromptu/symbol'
|
5
|
+
require 'impromptu/ordered_set'
|
6
|
+
require 'impromptu/component_set'
|
7
|
+
require 'impromptu/resource'
|
8
|
+
require 'impromptu/file'
|
9
|
+
require 'impromptu/folder'
|
10
|
+
require 'impromptu/component'
|
11
|
+
require 'impromptu/impromptu'
|
12
|
+
require 'impromptu/autoload'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
component 'framework' do
|
2
|
+
namespace :Framework
|
3
|
+
requires 'mathn'
|
4
|
+
folder 'lib', nested_namespaces: false
|
5
|
+
end
|
6
|
+
|
7
|
+
component 'framework.extensions' do
|
8
|
+
namespace :Framework
|
9
|
+
folder 'ext'
|
10
|
+
end
|
11
|
+
|
12
|
+
component 'other' do
|
13
|
+
folder 'other' do
|
14
|
+
file 'load.rb'
|
15
|
+
file 'also.rb', :provides => :OtherName
|
16
|
+
file 'two.rb', :provides => [:ModOne, :ModTwo, :OtherName]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
component 'private' do
|
21
|
+
namespace :Framework
|
22
|
+
folder 'private'
|
23
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAutload < Test::Unit::TestCase
|
4
|
+
context "A component with a namespace and no resources" do
|
5
|
+
setup do
|
6
|
+
Impromptu.reset
|
7
|
+
Impromptu.define_components do
|
8
|
+
component 'test' do
|
9
|
+
namespace :Namespace
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have a single component with a namespace" do
|
15
|
+
assert_equal 1, Impromptu.components.size
|
16
|
+
assert_equal :Namespace, Impromptu.components['test'].namespace
|
17
|
+
assert_not_nil Impromptu.root_resource.child(:Namespace)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "be able to have the namespace loaded using the autoload extension" do
|
21
|
+
assert_nothing_raised do
|
22
|
+
::Namespace
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
should "raise an appropriate exception when accessing a non existant resource" do
|
27
|
+
assert_raise NameError do
|
28
|
+
::IDontExistSoRaiseAnException
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestComponent < Test::Unit::TestCase
|
4
|
+
context "A new component" do
|
5
|
+
setup { @component = Impromptu::Component.new(nil, 'component') }
|
6
|
+
should "have a default path of the cwd" do
|
7
|
+
assert_equal Pathname.new('.').realpath, @component.base_path
|
8
|
+
end
|
9
|
+
|
10
|
+
should "respond to :requires" do
|
11
|
+
assert_respond_to @component, :requires
|
12
|
+
end
|
13
|
+
|
14
|
+
should "respond to :namespace" do
|
15
|
+
assert_respond_to @component, :namespace
|
16
|
+
end
|
17
|
+
|
18
|
+
should "respond to :folder" do
|
19
|
+
assert_respond_to @component, :folder
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have a name" do
|
23
|
+
assert_not_nil @component.name
|
24
|
+
end
|
25
|
+
|
26
|
+
should "have no requirements" do
|
27
|
+
assert_equal 0, @component.requirements.size
|
28
|
+
end
|
29
|
+
|
30
|
+
should "have no folders" do
|
31
|
+
assert_equal 0, @component.folders.size
|
32
|
+
end
|
33
|
+
|
34
|
+
# ----------------------------------------
|
35
|
+
# Requirements
|
36
|
+
# ----------------------------------------
|
37
|
+
context "with two requirements" do
|
38
|
+
setup { @component.requires('gem', 'other') }
|
39
|
+
should "store two requirements" do
|
40
|
+
assert_equal 2, @component.requirements.size
|
41
|
+
end
|
42
|
+
|
43
|
+
context "and with two more, overlapping requirements" do
|
44
|
+
setup { @component.requires('another', 'gem') }
|
45
|
+
should "only store new requirements" do
|
46
|
+
assert_equal 3, @component.requirements.size
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# ----------------------------------------
|
52
|
+
# Namespaces
|
53
|
+
# ----------------------------------------
|
54
|
+
context "with a namespace" do
|
55
|
+
setup { @component.namespace(:Framework) }
|
56
|
+
should "have a namespace" do
|
57
|
+
assert_equal :Framework, @component.namespace
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# ----------------------------------------
|
62
|
+
# Folders
|
63
|
+
# ----------------------------------------
|
64
|
+
context "with a folder" do
|
65
|
+
setup { @component.folder(['test', 'framework']) }
|
66
|
+
should "have one folder" do
|
67
|
+
assert_equal 1, @component.folders.size
|
68
|
+
end
|
69
|
+
|
70
|
+
should "have a folder that is a folder" do
|
71
|
+
assert_instance_of Impromptu::Folder, @component.folders.first
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# ----------------------------------------
|
76
|
+
# Freezing
|
77
|
+
# ----------------------------------------
|
78
|
+
should "be able to be frozen" do
|
79
|
+
assert_respond_to @component, :freeze
|
80
|
+
assert_respond_to @component, :frozen?
|
81
|
+
end
|
82
|
+
|
83
|
+
should "not be frozen by default" do
|
84
|
+
assert_equal false, @component.frozen?
|
85
|
+
end
|
86
|
+
|
87
|
+
context "which is frozen" do
|
88
|
+
setup { @component.freeze }
|
89
|
+
should "be frozen after calling freeze" do
|
90
|
+
assert_equal true, @component.frozen?
|
91
|
+
end
|
92
|
+
|
93
|
+
should "raise an exception when being modified" do
|
94
|
+
assert_raise RuntimeError do
|
95
|
+
@component.requires('ignored')
|
96
|
+
end
|
97
|
+
assert_raise RuntimeError do
|
98
|
+
@component.folder('ignored')
|
99
|
+
end
|
100
|
+
assert_raise RuntimeError do
|
101
|
+
@component.namespace(:Ignored)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# ----------------------------------------
|
107
|
+
# Loading dependencies
|
108
|
+
# ----------------------------------------
|
109
|
+
context "with some external requirements" do
|
110
|
+
setup { @component.requires 'matrix' }
|
111
|
+
should "ensure unloaded requirements are not already loaded" do
|
112
|
+
assert_raise NameError do
|
113
|
+
Matrix
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
should "load external requirements when requested" do
|
118
|
+
success = @component.load_external_dependencies
|
119
|
+
assert_equal true, success
|
120
|
+
assert_nothing_raised do
|
121
|
+
Matrix
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
should "only load requirements once" do
|
126
|
+
success = @component.load_external_dependencies
|
127
|
+
assert_equal true, success
|
128
|
+
success = @component.load_external_dependencies
|
129
|
+
assert_equal false, success
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestComponentSet < Test::Unit::TestCase
|
4
|
+
context "A component set with two components" do
|
5
|
+
setup do
|
6
|
+
@set = Impromptu::ComponentSet.new
|
7
|
+
@a = @set << Impromptu::Component.new(nil, 'a')
|
8
|
+
@b = @set << Impromptu::Component.new(nil, 'b')
|
9
|
+
end
|
10
|
+
|
11
|
+
should "have two components" do
|
12
|
+
assert_equal 2, @set.size
|
13
|
+
end
|
14
|
+
|
15
|
+
should "be able to find both components by name" do
|
16
|
+
assert_equal @a, @set['a']
|
17
|
+
assert_equal @b, @set['b']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/test_folder.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestImpromptu < Test::Unit::TestCase
|
4
|
+
context "Impromptu" do
|
5
|
+
should "respond to root_resource" do
|
6
|
+
assert_respond_to Impromptu, :root_resource
|
7
|
+
end
|
8
|
+
|
9
|
+
should "respond to components" do
|
10
|
+
assert_respond_to Impromptu, :components
|
11
|
+
end
|
12
|
+
|
13
|
+
should "respond to reset" do
|
14
|
+
assert_respond_to Impromptu, :reset
|
15
|
+
end
|
16
|
+
|
17
|
+
should "respond to define_components" do
|
18
|
+
assert_respond_to Impromptu, :define_components
|
19
|
+
end
|
20
|
+
|
21
|
+
should "respond to parse_file" do
|
22
|
+
assert_respond_to Impromptu, :parse_file
|
23
|
+
end
|
24
|
+
|
25
|
+
should "respond to component" do
|
26
|
+
assert_respond_to Impromptu, :component
|
27
|
+
end
|
28
|
+
|
29
|
+
should "return a resource from root_resource" do
|
30
|
+
assert_instance_of Impromptu::Resource, Impromptu.root_resource
|
31
|
+
end
|
32
|
+
|
33
|
+
should "return a component set from components" do
|
34
|
+
assert_instance_of Impromptu::ComponentSet, Impromptu.components
|
35
|
+
end
|
36
|
+
|
37
|
+
should "rase an exception if a block is not supplied to define_components" do
|
38
|
+
assert_raise RuntimeError do
|
39
|
+
Impromptu.define_components
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|