qor_dsl 0.1.5 → 0.2.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/README.md +1 -1
- data/example/gemfile.rb +1 -1
- data/lib/qor_dsl/class_method.rb +11 -8
- data/lib/qor_dsl/node.rb +3 -8
- data/lib/qor_dsl.rb +8 -0
- data/qor_dsl.gemspec +1 -1
- data/test/configure.rb +1 -1
- data/test/layout_test.rb +72 -53
- metadata +4 -4
data/README.md
CHANGED
@@ -78,7 +78,7 @@ Qor Dsl - DSL made easy!
|
|
78
78
|
Gemfile.deep_find(:gem) do |n|
|
79
79
|
# Find all gems used in development environment
|
80
80
|
parent = n.parent
|
81
|
-
parent.root? ||
|
81
|
+
parent.root? || parent.is_node?(:group, :development)
|
82
82
|
end
|
83
83
|
|
84
84
|
# Qor DSL is designed to be as flexible as possible while helping you to create your DSLs.
|
data/example/gemfile.rb
CHANGED
@@ -34,7 +34,7 @@ Gemfile.deep_find(:gem)
|
|
34
34
|
Gemfile.deep_find(:gem) do |n|
|
35
35
|
# Find all gems used in development environment
|
36
36
|
parent = n.parent
|
37
|
-
parent.root? ||
|
37
|
+
parent.root? || parent.is_node?(:group, :development)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Methods for node
|
data/lib/qor_dsl/class_method.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Qor
|
2
2
|
module Dsl
|
3
3
|
module ClassMethods
|
4
|
+
@@lock = Mutex.new
|
4
5
|
def node_root
|
5
6
|
@node_root ||= Qor::Dsl::Node.new
|
6
7
|
end
|
@@ -33,15 +34,17 @@ module Qor
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def load(path=nil, opts={}, &block)
|
36
|
-
|
37
|
+
@@lock.synchronize do
|
38
|
+
reset! if opts[:force] || block_given?
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
@root ||= if block_given? # Load from block
|
41
|
+
node_root.config.instance_eval(&block)
|
42
|
+
node_root
|
43
|
+
else # Load from file
|
44
|
+
@load_path = path || @load_path || default_config
|
45
|
+
load_file(@load_path)
|
46
|
+
end
|
47
|
+
end
|
45
48
|
end
|
46
49
|
|
47
50
|
def load_file(file)
|
data/lib/qor_dsl/node.rb
CHANGED
@@ -20,11 +20,8 @@ module Qor
|
|
20
20
|
root == self
|
21
21
|
end
|
22
22
|
|
23
|
-
def is_node?(
|
24
|
-
|
25
|
-
result = (config_name.to_s == arguments[0].to_s) if arguments.length >= 1
|
26
|
-
result = result && (name.to_s == arguments[1].to_s) if arguments.length == 2
|
27
|
-
return result
|
23
|
+
def is_node?(cname=nil, sname=nil)
|
24
|
+
(cname.nil? || (config_name.to_s == cname.to_s)) && (sname.nil? || (name.to_s == sname.to_s))
|
28
25
|
end
|
29
26
|
|
30
27
|
def root
|
@@ -80,9 +77,7 @@ module Qor
|
|
80
77
|
|
81
78
|
def find(type=nil, name=nil, nodes=children, &block)
|
82
79
|
selected_children = nodes.select do |child|
|
83
|
-
(type.nil? ? true : (child
|
84
|
-
(name.nil? ? true : (child.name.to_s == name.to_s)) &&
|
85
|
-
(block.nil? ? true : block.call(child))
|
80
|
+
child.is_node?(type, name) && (block.nil? ? true : block.call(child))
|
86
81
|
end
|
87
82
|
|
88
83
|
return selected_children[0] if !name.nil? && selected_children.length == 1
|
data/lib/qor_dsl.rb
CHANGED
data/qor_dsl.gemspec
CHANGED
data/test/configure.rb
CHANGED
data/test/layout_test.rb
CHANGED
@@ -2,86 +2,105 @@ require 'minitest/autorun'
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'configure')
|
3
3
|
|
4
4
|
describe Layout do
|
5
|
+
def many_times
|
6
|
+
threads = 100.times.map do |t|
|
7
|
+
Thread.new do
|
8
|
+
yield
|
9
|
+
end
|
10
|
+
end
|
11
|
+
threads.map(&:join)
|
12
|
+
end
|
13
|
+
|
5
14
|
it "layout config testing" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
many_times do
|
16
|
+
Layout::Configuration.load('test/layout.rb', :force => true)
|
17
|
+
# Find by type
|
18
|
+
Layout::Configuration.find(:gadget).length.must_equal 2
|
19
|
+
Layout::Configuration.find(:template).length.must_equal 2
|
20
|
+
Layout::Configuration.deep_find(:template).length.must_equal 3
|
21
|
+
# :settings, :meta, :meta, :meta, :meta, :context, :template
|
22
|
+
Layout::Configuration.find(:gadget, :quick_buy).deep_find().length.must_equal 7
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
24
|
+
# Find by name
|
25
|
+
Layout::Configuration.find(:gadget, 'quick_buy').name.must_equal :quick_buy
|
26
|
+
Layout::Configuration.deep_find(:desc, "From Google").value.must_equal "From Google"
|
17
27
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
28
|
+
# Find by block
|
29
|
+
Layout::Configuration.first(:template) do |n|
|
30
|
+
n.options[:since] > "12:50"
|
31
|
+
end.value.must_equal 'Hello World2'
|
22
32
|
|
23
|
-
|
24
|
-
|
25
|
-
|
33
|
+
Layout::Configuration.deep_find(:desc) do |n|
|
34
|
+
n.parents.include?(Layout::Configuration.find(:action, :google))
|
35
|
+
end[0].value.must_equal 'From Google'
|
26
36
|
|
27
|
-
|
28
|
-
|
37
|
+
# Inherit
|
38
|
+
Layout::Configuration.find(:gadget, :product_link).find(:template)[0].value.must_equal "Hello World"
|
29
39
|
|
30
|
-
|
31
|
-
|
40
|
+
# Store any data
|
41
|
+
Layout::Configuration.first(:template).data.must_equal ["v1", {:since => "09:00", :to => "12:00"}]
|
32
42
|
|
33
|
-
|
34
|
-
|
43
|
+
# Options
|
44
|
+
Layout::Configuration.find(:template)[1].options.must_equal({:since => "13:00", :to => "18:00"})
|
35
45
|
|
36
|
-
|
37
|
-
|
46
|
+
# Parents
|
47
|
+
Layout::Configuration.find(:gadget, :quick_buy).first(:template).parents.count.must_equal 2
|
38
48
|
|
39
|
-
|
40
|
-
|
49
|
+
# Value for node
|
50
|
+
Layout::Configuration.find(:gadget, :quick_buy).value.must_equal :quick_buy
|
41
51
|
|
42
|
-
|
52
|
+
Layout::Configuration.find(:gadget, :quick_buy).value.must_equal :quick_buy
|
53
|
+
end
|
43
54
|
# More is coming... (multi, alias_node)
|
44
55
|
end
|
45
56
|
|
46
57
|
it "test node helper" do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
58
|
+
many_times do
|
59
|
+
Layout::Configuration.load('test/layout.rb', :force => true)
|
60
|
+
node = Layout::Configuration.find(:gadget, :quick_buy)
|
61
|
+
node.is_node?(:gadget).must_equal true
|
62
|
+
node.is_node?(:gadget, 'quick_buy').must_equal true
|
63
|
+
node.is_node?(:template).must_equal false
|
64
|
+
node.is_node?('gadget').must_equal true
|
65
|
+
node.is_node?.must_equal true
|
66
|
+
end
|
54
67
|
end
|
55
68
|
|
56
69
|
it "force load" do
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
70
|
+
many_times do
|
71
|
+
Layout::Configuration.load('test/layout.rb', :force => true)
|
72
|
+
root = Layout::Configuration.root
|
73
|
+
root.find(:gadget).length.must_equal 2
|
74
|
+
old_object_ids = root.find(:gadget).map(&:object_id).sort
|
61
75
|
|
62
|
-
|
63
|
-
|
76
|
+
Layout::Configuration.load('test/layout.rb')
|
77
|
+
root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
|
64
78
|
|
65
|
-
|
66
|
-
|
79
|
+
Layout::Configuration.load('test/layout.rb', :force => true)
|
80
|
+
new_root = Layout::Configuration.root
|
67
81
|
|
68
|
-
|
69
|
-
|
70
|
-
|
82
|
+
new_root.find(:gadget).length.must_equal 2
|
83
|
+
root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
|
84
|
+
new_root.find(:gadget).map(&:object_id).sort.wont_be_same_as old_object_ids
|
85
|
+
end
|
71
86
|
end
|
72
87
|
|
73
88
|
it "load config from block" do
|
74
|
-
|
75
|
-
|
76
|
-
"
|
89
|
+
many_times do
|
90
|
+
Layout::Configuration.load(nil, :force => true) do
|
91
|
+
template "new" do
|
92
|
+
"New Template"
|
93
|
+
end
|
77
94
|
end
|
78
|
-
end
|
79
95
|
|
80
|
-
|
81
|
-
|
96
|
+
Layout::Configuration.find(:template).count.must_equal 1
|
97
|
+
Layout::Configuration.first(:template).value.must_equal "New Template"
|
98
|
+
end
|
82
99
|
end
|
83
100
|
|
84
101
|
it "should raise exception if configuration not found" do
|
85
|
-
|
102
|
+
many_times do
|
103
|
+
lambda { Layout::Configuration.load("non_existing_file.rb", :force => true) }.must_raise Qor::Dsl::ConfigurationNotFound
|
104
|
+
end
|
86
105
|
end
|
87
106
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qor_dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Qor DSL is designed to be as flexible as possible while helping you to
|
15
15
|
create your DSLs.
|
@@ -48,7 +48,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
48
|
version: '0'
|
49
49
|
segments:
|
50
50
|
- 0
|
51
|
-
hash:
|
51
|
+
hash: 3416388606378692493
|
52
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
version: '0'
|
58
58
|
segments:
|
59
59
|
- 0
|
60
|
-
hash:
|
60
|
+
hash: 3416388606378692493
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
63
|
rubygems_version: 1.8.24
|