alki-dsl 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74a68f3b18db59488fcbe8c2037b3933f33aef5d
4
- data.tar.gz: '070150789ebbd1bc8b2615395c3e803c0b259913'
3
+ metadata.gz: 4d2cf31784168eb5de6e6fd04ac4d6d7763aa16a
4
+ data.tar.gz: '0299ce32b0c21d2567c6a201696262a0442af954'
5
5
  SHA512:
6
- metadata.gz: 420aa794f86a9c2339e784cabd08260d304f500e4c6d6b9731e4b66c7d607153f89a6e1fb3f570a54040a475b7c16e0dbed658f237fd5bab1ee163cbc1e84742
7
- data.tar.gz: 2a8a0cc25a0fe87a36fe278f5c3ee4768d4816650ead0354dda92e4861ff15e418e5b263ac04e78ef009db02303da87cacc6d996cf667e252dda54d5c2ec2eea
6
+ metadata.gz: b306403e0261d49b4d4f5f16203d7599cc8468d5b1cb9cfa57e546dbc7be2f872590c4bc0d444037370d6a863b47358e1dda0027aecf7b3f532aeeb892a41feb
7
+ data.tar.gz: 525dfdbe6892594eda9330edfde6c7b77bf63ccfec42915f20fd7495d89f22dc459a5140ccc20a9566975616a75feb9a7b5bc08d49de7966ba75ebfd7d37a82a
data/alki-dsl.gemspec CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency 'alki-support', '~> 0.7'
21
- spec.add_dependency 'alki-loader', '~> 0.1'
21
+ spec.add_dependency 'alki-loader', '~> 0.2'
22
22
  spec.add_development_dependency 'minitest', '~> 5.9', '>= 5.9.1'
23
23
  end
@@ -85,12 +85,12 @@ module Alki
85
85
 
86
86
  if data[:modules]
87
87
  data[:modules].each do |mod|
88
- klass.include mod
88
+ klass.include Alki.load mod
89
89
  end
90
90
  end
91
91
  if data[:class_modules]
92
92
  data[:class_modules].each do |mod|
93
- klass.extend mod
93
+ klass.extend Alki.load mod
94
94
  end
95
95
  end
96
96
 
data/lib/alki/dsl.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  require 'alki/loader'
2
+ require 'alki/dsl/merge'
2
3
 
3
4
  module Alki
4
5
  module Dsl
6
+ def self.merge(*dsls)
7
+ Alki::Dsl::Merge.new *dsls
8
+ end
9
+
5
10
  def self.build(name,data={},&blk)
6
11
  Alki.load(name).build data, &blk
7
12
  end
data/lib/alki/dsl/base.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  require 'alki/support'
2
- require 'alki/dsl/evaluator'
2
+ require 'alki/dsl/builder'
3
3
 
4
4
  module Alki
5
5
  module Dsl
6
6
  class Base
7
- def self.build(data={},&blk)
8
- Alki::Dsl::Evaluator.evaluate self, data, &blk
9
- end
7
+ extend Alki::Dsl::Builder
10
8
 
11
9
  def self.generate(ctx)
12
10
  obj = new(ctx)
@@ -16,7 +14,6 @@ module Alki
16
14
  result[:init] = obj.method(info[:init]) if info[:init]
17
15
  result[:finish] = obj.method(info[:finish]) if info[:finish]
18
16
  result[:requires] = info[:requires] if info[:requires]
19
- result[:helpers] = info[:helpers] if info[:helpers]
20
17
 
21
18
  if info[:methods]
22
19
  info[:methods].each do |method|
@@ -35,6 +32,14 @@ module Alki
35
32
  {}
36
33
  end
37
34
 
35
+ def self.helpers
36
+ if defined? self::Helpers
37
+ [self::Helpers]
38
+ else
39
+ []
40
+ end
41
+ end
42
+
38
43
  def initialize(ctx)
39
44
  @ctx = ctx
40
45
  end
@@ -42,4 +47,4 @@ module Alki
42
47
  attr_reader :ctx
43
48
  end
44
49
  end
45
- end
50
+ end
@@ -0,0 +1,11 @@
1
+ require 'alki/dsl/evaluator'
2
+
3
+ module Alki
4
+ module Dsl
5
+ module Builder
6
+ def build(data={},&blk)
7
+ Alki::Dsl::Evaluator.evaluate self, data, &blk
8
+ end
9
+ end
10
+ end
11
+ end
@@ -48,13 +48,11 @@ module Alki
48
48
  end
49
49
 
50
50
  def add_helper(name,&blk)
51
- class_builder('Helpers')[:type] = :module
52
51
  add_method name, &blk
53
52
  add_method name, subclass: 'Helpers', &blk
54
53
  end
55
54
 
56
55
  def add_helper_module(mod)
57
- class_builder('Helpers')[:type] = :module
58
56
  add_module mod
59
57
  add_module mod, subclass: 'Helpers'
60
58
  end
@@ -16,6 +16,9 @@ module Alki
16
16
  process_dsl dsl, data
17
17
 
18
18
  @inits.each(&:call)
19
+ define_dsl_method mod, :method_missing do |meth,*args,&b|
20
+ blk.binding.receiver.send meth, *args, &b
21
+ end
19
22
  dsl_exec mod, &blk
20
23
  @finishers.reverse_each(&:call)
21
24
  clear_dsl_methods mod
@@ -0,0 +1,26 @@
1
+ require 'alki/dsl/builder'
2
+
3
+ module Alki
4
+ module Dsl
5
+ class Merge
6
+ include Alki::Dsl::Builder
7
+
8
+ def initialize(*dsls)
9
+ @dsls = dsls
10
+ @requires = dsls.map{|dsl| [dsl,:before]}.freeze
11
+ end
12
+
13
+ def generate(_ctx)
14
+ {
15
+ requires: @requires
16
+ }
17
+ end
18
+
19
+ def helpers
20
+ @helpers ||= @dsls.inject([]) do |helpers, dsl|
21
+ helpers.push *Alki.load(dsl).helpers
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module Alki
2
2
  module Dsl
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.2'
4
4
  end
5
5
  end
data/lib/alki/dsls/dsl.rb CHANGED
@@ -50,11 +50,11 @@ module Alki
50
50
  end
51
51
 
52
52
  def require_dsl(dsl, order=:before)
53
- dsl_class = Alki.load(dsl)
54
- @info[:requires] << [dsl_class,order]
55
- if defined? dsl_class::Helpers
56
- add_module dsl_class::Helpers
57
- add_helper_module dsl_class::Helpers
53
+ dsl_class = Alki.load dsl
54
+ @info[:requires] << [dsl,order]
55
+ dsl_class.helpers.each do |helper|
56
+ add_module helper
57
+ add_helper_module helper
58
58
  end
59
59
  end
60
60
 
@@ -68,6 +68,10 @@ module Alki
68
68
 
69
69
  def finish
70
70
  set_super_class 'alki/dsl/base'
71
+ class_builder('Helpers')[:type] = :module
72
+ add_class_method :helpers do
73
+ [self::Helpers]
74
+ end
71
75
  info = @info.freeze
72
76
  add_class_method :dsl_info do
73
77
  info
@@ -16,4 +16,9 @@ describe 'dsl configuration' do
16
16
  require 'alki_test/numbers/three'
17
17
  AlkiTest::Numbers::Three.new.must_equal 3
18
18
  end
19
+
20
+ it 'should allow using Alki::Dsl.merge to merge dsls together' do
21
+ require 'alki_test/numbers/three'
22
+ AlkiTest::Numbers::Three.simple.must_equal true
23
+ end
19
24
  end
@@ -1,2 +1,3 @@
1
- Alki::Loader.register '../numbers', builder: 'alki_test/dsls/number', name: 'alki_test/numbers'
1
+ number_dsl = Alki::Dsl.merge 'alki_test/dsls/number', 'alki_test/dsls/simple'
2
+ Alki::Loader.register '../numbers', builder: number_dsl, name: 'alki_test/numbers'
2
3
  Alki::Loader.register 'alki_test/dsls', builder: 'alki/dsls/dsl'
@@ -0,0 +1,9 @@
1
+ Alki do
2
+ require_dsl 'alki/dsls/class'
3
+
4
+ finish do
5
+ add_class_method :simple do
6
+ true
7
+ end
8
+ end
9
+ end
@@ -60,7 +60,9 @@ describe Alki::ClassBuilder do
60
60
 
61
61
  it 'should allow setting super class by name' do
62
62
  class AlkiTestClass; end
63
- build(super_class: 'alki_test_class').superclass.must_equal AlkiTestClass
63
+ Alki.stub(:load,AlkiTestClass) do
64
+ build(super_class: 'alki_test_class').superclass.must_equal AlkiTestClass
65
+ end
64
66
  Object.send :remove_const, :AlkiTestClass
65
67
  end
66
68
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alki-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Edlefsen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-29 00:00:00.000000000 Z
11
+ date: 2017-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alki-support
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '0.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: '0.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,17 @@ files:
72
72
  - lib/alki/class_builder.rb
73
73
  - lib/alki/dsl.rb
74
74
  - lib/alki/dsl/base.rb
75
+ - lib/alki/dsl/builder.rb
75
76
  - lib/alki/dsl/class_helpers.rb
76
77
  - lib/alki/dsl/evaluator.rb
78
+ - lib/alki/dsl/merge.rb
77
79
  - lib/alki/dsl/version.rb
78
80
  - lib/alki/dsls/class.rb
79
81
  - lib/alki/dsls/dsl.rb
80
82
  - test/feature/config_test.rb
81
83
  - test/fixtures/example/lib/alki_loader.rb
82
84
  - test/fixtures/example/lib/alki_test/dsls/number.rb
85
+ - test/fixtures/example/lib/alki_test/dsls/simple.rb
83
86
  - test/fixtures/example/lib/alki_test/dsls/value.rb
84
87
  - test/fixtures/example/numbers/three.rb
85
88
  - test/integration/class_builder_test.rb
@@ -113,6 +116,7 @@ test_files:
113
116
  - test/feature/config_test.rb
114
117
  - test/fixtures/example/lib/alki_loader.rb
115
118
  - test/fixtures/example/lib/alki_test/dsls/number.rb
119
+ - test/fixtures/example/lib/alki_test/dsls/simple.rb
116
120
  - test/fixtures/example/lib/alki_test/dsls/value.rb
117
121
  - test/fixtures/example/numbers/three.rb
118
122
  - test/integration/class_builder_test.rb