qor_dsl 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ capybara-*.html
15
15
  rerun.txt
16
16
  pickle-email-*.html
17
17
  pkg/
18
+ Gemfile.lock
data/README.md CHANGED
@@ -35,7 +35,7 @@ Qor Dsl - DSL made easy!
35
35
 
36
36
  3, Defining config (Sample Gemfile file used for above config)
37
37
 
38
- # Gemfile
38
+ # Using default config file `Gemfile`
39
39
  source 'http://rubygems.org'
40
40
 
41
41
  gem 'rails', '3.2.8'
@@ -50,7 +50,15 @@ Qor Dsl - DSL made easy!
50
50
  gem 'rspec'
51
51
  end
52
52
 
53
- 4, Querying config (Please checkout the source code and play with examples under the /example directory for more details)
53
+ # Or using code block
54
+ Gemfile.load do
55
+ source 'http://rubygems.org'
56
+
57
+ gem 'rails', '3.2.8'
58
+ gem 'unicorn'
59
+ end
60
+
61
+ 4, Querying config (Please checkout the source code and play with examples under the `example` directory for more details)
54
62
 
55
63
  # Find by type
56
64
  Gemfile.find(:gem)
@@ -5,6 +5,13 @@ module Qor
5
5
  @node_root ||= Qor::Dsl::Node.new
6
6
  end
7
7
 
8
+ def reset!
9
+ node_config = node_root.config
10
+ @node_root = Qor::Dsl::Node.new
11
+ @node_root.add_config(node_config)
12
+ @root = nil
13
+ end
14
+
8
15
  def node(type, options={}, &blk)
9
16
  node_root.node(type, options, &blk)
10
17
  end
@@ -25,18 +32,21 @@ module Qor
25
32
  end
26
33
  end
27
34
 
28
- def load(path=nil, opts={})
29
- @load_path, @root = nil, nil if opts[:force]
35
+ def load(path=nil, opts={}, &block)
36
+ reset! if opts[:force] || block_given?
30
37
 
31
- @load_path = path || @load_path || default_config
32
- @root ||= load_file(@load_path)
33
- @root
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
34
45
  end
35
46
 
36
47
  def load_file(file)
37
48
  return unless File.exist?(file.to_s)
38
- content = File.read(file)
39
- node_root.config.instance_eval(content)
49
+ node_root.config.instance_eval(File.read(file))
40
50
  node_root
41
51
  end
42
52
 
@@ -44,7 +44,7 @@ module Qor
44
44
  result = [
45
45
  ['name', __name],
46
46
  ['parent', __parent && __parent.__name],
47
- ['__children', __children.keys],
47
+ ['children', __children.keys],
48
48
  ['options', __options],
49
49
  ['block', __block]
50
50
  ].inject({}) do |s, value|
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.1"
14
+ gem.version = "0.1.3"
15
15
  end
data/test/layout_test.rb CHANGED
@@ -2,12 +2,8 @@ require 'minitest/autorun'
2
2
  require File.join(File.dirname(__FILE__), 'configure')
3
3
 
4
4
  describe Layout do
5
- before do
6
- Layout::Configuration.load('test/layout.rb')
7
- @root = Layout::Configuration.root
8
- end
9
-
10
5
  it "layout config testing" do
6
+ Layout::Configuration.load('test/layout.rb', :force => true)
11
7
  # Find by type
12
8
  Layout::Configuration.find(:gadget).length.must_equal 2
13
9
  Layout::Configuration.find(:template).length.must_equal 2
@@ -45,4 +41,32 @@ describe Layout do
45
41
 
46
42
  # More is coming... (multi, alias_node)
47
43
  end
44
+
45
+ it "force load" do
46
+ Layout::Configuration.load('test/layout.rb', :force => true)
47
+ root = Layout::Configuration.root
48
+ root.find(:gadget).length.must_equal 2
49
+ old_object_ids = root.find(:gadget).map(&:object_id).sort
50
+
51
+ Layout::Configuration.load('test/layout.rb')
52
+ root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
53
+
54
+ Layout::Configuration.load('test/layout.rb', :force => true)
55
+ new_root = Layout::Configuration.root
56
+
57
+ new_root.find(:gadget).length.must_equal 2
58
+ root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
59
+ new_root.find(:gadget).map(&:object_id).sort.wont_be_same_as old_object_ids
60
+ end
61
+
62
+ it "load config from block" do
63
+ Layout::Configuration.load(nil, :force => true) do
64
+ template "new" do
65
+ "New Template"
66
+ end
67
+ end
68
+
69
+ Layout::Configuration.find(:template).count.must_equal 1
70
+ Layout::Configuration.first(:template).value.must_equal "New Template"
71
+ end
48
72
  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.1
4
+ version: 0.1.3
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-21 00:00:00.000000000 Z
12
+ date: 2012-10-22 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.
@@ -21,7 +21,6 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
23
  - Gemfile
24
- - Gemfile.lock
25
24
  - README.md
26
25
  - Rakefile
27
26
  - example/Gemfile
data/Gemfile.lock DELETED
@@ -1,14 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- qor_dsl (0.0.5)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
-
10
- PLATFORMS
11
- ruby
12
-
13
- DEPENDENCIES
14
- qor_dsl!