qor_dsl 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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? || ((parent.config_name == :group) && parent.name == :development)
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? || ((parent.config_name == :group) && parent.name == :development)
37
+ parent.root? || parent.is_node?(:group, :development)
38
38
  end
39
39
 
40
40
  # Methods for node
@@ -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
- reset! if opts[:force] || block_given?
37
+ @@lock.synchronize do
38
+ reset! if opts[:force] || block_given?
37
39
 
38
- @root ||= if block_given? # Load from block
39
- node_root.config.instance_eval(&block)
40
- node_root
41
- else # Load from file
42
- @load_path = path || @load_path || default_config
43
- load_file(@load_path)
44
- end
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?(*arguments)
24
- result = true
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.config_name.to_s == type.to_s)) &&
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
@@ -19,3 +19,11 @@ module Qor
19
19
  end
20
20
  end
21
21
  end
22
+
23
+ module Qor
24
+ module DSL
25
+ def self.included(base)
26
+ base.send :include, Qor::Dsl
27
+ end
28
+ end
29
+ end
data/qor_dsl.gemspec CHANGED
@@ -11,5 +11,5 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
12
  gem.name = "qor_dsl"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "0.1.5"
14
+ gem.version = "0.2.0"
15
15
  end
data/test/configure.rb CHANGED
@@ -2,7 +2,7 @@ require 'qor_dsl'
2
2
 
3
3
  module Layout
4
4
  module Configuration
5
- include Qor::Dsl
5
+ include Qor::DSL
6
6
 
7
7
  node :template
8
8
 
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
- Layout::Configuration.load('test/layout.rb', :force => true)
7
- # Find by type
8
- Layout::Configuration.find(:gadget).length.must_equal 2
9
- Layout::Configuration.find(:template).length.must_equal 2
10
- Layout::Configuration.deep_find(:template).length.must_equal 3
11
- # :settings, :meta, :meta, :meta, :meta, :context, :template
12
- Layout::Configuration.find(:gadget, :quick_buy).deep_find().length.must_equal 7
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
- # Find by name
15
- Layout::Configuration.find(:gadget, 'quick_buy').name.must_equal :quick_buy
16
- Layout::Configuration.deep_find(:desc, "From Google").value.must_equal "From Google"
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
- # Find by block
19
- Layout::Configuration.first(:template) do |n|
20
- n.options[:since] > "12:50"
21
- end.value.must_equal 'Hello World2'
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
- Layout::Configuration.deep_find(:desc) do |n|
24
- n.parents.include?(Layout::Configuration.find(:action, :google))
25
- end[0].value.must_equal 'From Google'
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
- # Inherit
28
- Layout::Configuration.find(:gadget, :product_link).find(:template)[0].value.must_equal "Hello World"
37
+ # Inherit
38
+ Layout::Configuration.find(:gadget, :product_link).find(:template)[0].value.must_equal "Hello World"
29
39
 
30
- # Store any data
31
- Layout::Configuration.first(:template).data.must_equal ["v1", {:since => "09:00", :to => "12:00"}]
40
+ # Store any data
41
+ Layout::Configuration.first(:template).data.must_equal ["v1", {:since => "09:00", :to => "12:00"}]
32
42
 
33
- # Options
34
- Layout::Configuration.find(:template)[1].options.must_equal({:since => "13:00", :to => "18:00"})
43
+ # Options
44
+ Layout::Configuration.find(:template)[1].options.must_equal({:since => "13:00", :to => "18:00"})
35
45
 
36
- # Parents
37
- Layout::Configuration.find(:gadget, :quick_buy).first(:template).parents.count.must_equal 2
46
+ # Parents
47
+ Layout::Configuration.find(:gadget, :quick_buy).first(:template).parents.count.must_equal 2
38
48
 
39
- # Value for node
40
- Layout::Configuration.find(:gadget, :quick_buy).value.must_equal :quick_buy
49
+ # Value for node
50
+ Layout::Configuration.find(:gadget, :quick_buy).value.must_equal :quick_buy
41
51
 
42
- Layout::Configuration.find(:gadget, :quick_buy).value.must_equal :quick_buy
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
- Layout::Configuration.load('test/layout.rb', :force => true)
48
- node = Layout::Configuration.find(:gadget, :quick_buy)
49
- node.is_node?(:gadget).must_equal true
50
- node.is_node?(:gadget, 'quick_buy').must_equal true
51
- node.is_node?(:template).must_equal false
52
- node.is_node?('gadget').must_equal true
53
- node.is_node?.must_equal true
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
- Layout::Configuration.load('test/layout.rb', :force => true)
58
- root = Layout::Configuration.root
59
- root.find(:gadget).length.must_equal 2
60
- old_object_ids = root.find(:gadget).map(&:object_id).sort
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
- Layout::Configuration.load('test/layout.rb')
63
- root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
76
+ Layout::Configuration.load('test/layout.rb')
77
+ root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
64
78
 
65
- Layout::Configuration.load('test/layout.rb', :force => true)
66
- new_root = Layout::Configuration.root
79
+ Layout::Configuration.load('test/layout.rb', :force => true)
80
+ new_root = Layout::Configuration.root
67
81
 
68
- new_root.find(:gadget).length.must_equal 2
69
- root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
70
- new_root.find(:gadget).map(&:object_id).sort.wont_be_same_as old_object_ids
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
- Layout::Configuration.load(nil, :force => true) do
75
- template "new" do
76
- "New Template"
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
- Layout::Configuration.find(:template).count.must_equal 1
81
- Layout::Configuration.first(:template).value.must_equal "New Template"
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
- lambda { Layout::Configuration.load("non_existing_file.rb", :force => true) }.must_raise Qor::Dsl::ConfigurationNotFound
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.1.5
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-24 00:00:00.000000000 Z
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: -139701006465928578
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: -139701006465928578
60
+ hash: 3416388606378692493
61
61
  requirements: []
62
62
  rubyforge_project:
63
63
  rubygems_version: 1.8.24