alki 0.4.1 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d03b924924111f899b88319c5fae18228e4a060
4
- data.tar.gz: 14231faa1ae0f3b455ecae08335b0b49198ee537
3
+ metadata.gz: b62e2164cbf952d15c45aa1845bdd03afac913b0
4
+ data.tar.gz: 749ebc7d797b44ec3ecd900d4cb48b2e45af625d
5
5
  SHA512:
6
- metadata.gz: 34d3014edc286dba4028867b4dac194e2982029ccc5bd430e87b34df0c4ab136c4e4899aac0c89e84f666ef3f422bfbb5635555e76b8f00afbf58c7f7a108d9e
7
- data.tar.gz: 4544b374525cb978fdd42fe39709cac0e1e47f6ab69dad77ab001dc942ff41bf9eae406c85df3a15319497c2574a3bd80800bb8d846c12eae38d7cbd00057e74
6
+ metadata.gz: 56a1e7009e25e8c846f13cbeefa8e5043f3d1148675534f6082358f8ed4de0f0a53f146af5ec19219e0d9ec9ecf618abb9e290e1db731d86d28b51cd133c6ef3
7
+ data.tar.gz: db587ec5e1a2a6f3594ec7081729b96aa666da5bc2ebceba4c3360fa723befb900c45e9c24e07d4d4c9b29f94a49af8c644ce491f41beb27516737a8c8b62893
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem 'pry'
6
-
7
- group :test do
8
- gem 'minitest', '~> 5.4.2'
9
- end
data/alki.gemspec CHANGED
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake", '~> 10.0'
23
23
  spec.add_dependency "minitest", "~> 5.9", '>= 5.9.1'
24
- spec.add_dependency "alki-dsl", "~> 0.2"
25
- spec.add_dependency "alki-support", "~> 0.4"
24
+ spec.add_dependency "alki-dsl", "~> 0.3"
25
+ spec.add_dependency "alki-support", "~> 0.5"
26
26
  end
data/lib/alki/assembly.rb CHANGED
@@ -3,15 +3,15 @@ require 'alki/assembly_executor'
3
3
  module Alki
4
4
  module Assembly
5
5
  def new
6
- Alki::Assembly::Instance.new assembly, load_path: config_root
6
+ Alki::Assembly::Instance.new assembly, self.assembly_options
7
7
  end
8
8
 
9
9
  def assembly
10
- self.assembly_class.assembly
10
+ self.definition.assembly
11
11
  end
12
12
 
13
13
  def root
14
- self.assembly_class.root
14
+ self.definition.root
15
15
  end
16
16
 
17
17
  class Instance
@@ -0,0 +1,102 @@
1
+ require 'alki/assembly'
2
+ require 'alki/class_builder'
3
+ require 'alki/dsl'
4
+ require 'alki/support'
5
+
6
+ module Alki
7
+ class AssemblyBuilder
8
+ def initialize
9
+ @assembly_options = {}
10
+ @assembly_name = nil
11
+ @definition = nil
12
+ end
13
+
14
+ attr_reader :assembly_options, :assembly_name, :definition
15
+
16
+ def self.build(opts={},&blk)
17
+ new.build(opts,&blk)
18
+ end
19
+
20
+ def build(opts={},&blk)
21
+ build_assembly blk if blk
22
+ set_config_directory opts[:config_dir] if opts[:config_dir]
23
+ set_assembly_name opts[:name] if opts[:name]
24
+ detect_from_path opts[:path] if opts[:path]
25
+ load_assembly_file opts[:primary_config] unless definition
26
+ build_empty_assembly unless definition
27
+ build_class
28
+ end
29
+
30
+ def detect_from_path(path)
31
+ root = Alki::Support.find_root(path) do |dir|
32
+ File.exists?(File.join(dir,'config','assembly.rb')) ||
33
+ File.exists?(File.join(dir,'Gemfile')) ||
34
+ !Dir.glob(File.join(dir,'*.gemspec')).empty?
35
+ end
36
+ if root
37
+ unless @assembly_options[:load_path]
38
+ config_dir = File.join(root,'config')
39
+ set_config_directory config_dir if File.exists? config_dir
40
+ end
41
+
42
+ unless @assembly_name
43
+ lib_dir = File.join(root,'lib')
44
+ name = Alki::Support.path_name path, lib_dir
45
+ unless name
46
+ raise "Can't auto-detect name of assembly"
47
+ end
48
+ set_assembly_name name
49
+ end
50
+ end
51
+ end
52
+
53
+ def set_assembly_name(name)
54
+ @assembly_name = name
55
+ end
56
+
57
+ def set_config_directory(config_dir)
58
+ Alki::Dsl.register_dir config_dir, 'alki/dsls/assembly'
59
+ @assembly_options[:load_path] = config_dir
60
+ end
61
+
62
+ def load_assembly_file(name = nil)
63
+ name ||= 'assembly'
64
+ if @assembly_options[:load_path]
65
+ assembly_config_path = File.join(@assembly_options[:load_path],"#{name}.rb")
66
+ if File.exists? assembly_config_path
67
+ @definition = Alki::Dsl.load(assembly_config_path)[:class]
68
+ true
69
+ end
70
+ end
71
+ end
72
+
73
+ def build_empty_assembly
74
+ build_assembly ->{}
75
+ end
76
+
77
+ def build_assembly(blk)
78
+ @definition = Alki::Dsl.build('alki/dsls/assembly', &blk)[:class]
79
+ end
80
+
81
+ def build_class
82
+ assembly_options = @assembly_options
83
+ definition = @definition
84
+ Alki::ClassBuilder.build(
85
+ prefix: '',
86
+ name: @assembly_name,
87
+ class_modules: [Alki::Assembly],
88
+ type: :module,
89
+ class_methods: {
90
+ definition: {
91
+ body: ->{
92
+ definition
93
+ }
94
+ },
95
+ assembly_options: {
96
+ body: ->{ assembly_options }
97
+ }
98
+ }
99
+ )
100
+ end
101
+ end
102
+ end
@@ -1,5 +1,6 @@
1
1
  require 'alki/service_delegator'
2
2
  require 'alki/overlay_delegator'
3
+ require 'alki/class_builder'
3
4
 
4
5
  module Alki
5
6
  class AssemblyExecutor
@@ -26,10 +27,8 @@ module Alki
26
27
  raise "Path not found: #{path.join('.')}" unless elem
27
28
  res = Resource.new assembly, cache, elem
28
29
  cache[path] = case elem[:type]
29
- when :service
30
- service res, path
31
- when :factory
32
- factory res, &blk
30
+ when :value
31
+ value res, path
33
32
  when :group
34
33
  group res
35
34
  end
@@ -37,6 +36,19 @@ module Alki
37
36
  cache[path].call *args, &blk
38
37
  end
39
38
 
39
+ def value(res,path)
40
+ evaluator = -> (value_block,*args,&blk) {
41
+ with_scope_context(res,value_block) do |ctx|
42
+ val = ctx.__call__(*args,&blk)
43
+ if res.elem[:overlays]
44
+ val = apply_overlays res, path, val
45
+ end
46
+ val
47
+ end
48
+ }
49
+ res.elem[:block].call evaluator
50
+ end
51
+
40
52
  def service(res,path)
41
53
  with_scope_context(res) do |ctx,blk|
42
54
  svc = apply_overlays res, path, ctx.instance_exec(&blk)
@@ -47,8 +59,8 @@ module Alki
47
59
  def apply_overlays(res,path,obj)
48
60
  res.elem[:overlays].inject(obj) do |obj,overlay_elem|
49
61
  unless res.cache[overlay_elem[:block]]
50
- with_scope_context(res.with_elem(overlay_elem)) do |ctx,blk|
51
- res.cache[overlay_elem[:block]] = ctx.instance_exec(&blk)
62
+ with_scope_context(res.with_elem(overlay_elem)) do |ctx|
63
+ res.cache[overlay_elem[:block]] = ctx.__call__
52
64
  end
53
65
  end
54
66
  local_path = path[overlay_elem[:scope][:root].size..-1].join('.')
@@ -60,11 +72,7 @@ module Alki
60
72
  with_scope_context(res) do |ctx,blk|
61
73
  factory = ctx.instance_exec(&blk)
62
74
  -> (*args,&blk) {
63
- if !args.empty? or blk
64
- factory.call *args, &blk
65
- else
66
- factory
67
- end
75
+ factory.call *args, &blk
68
76
  }
69
77
  end
70
78
  end
@@ -77,12 +85,19 @@ module Alki
77
85
  -> { group }
78
86
  end
79
87
 
80
- def with_scope_context(res)
88
+ def with_scope_context(res,blk = nil)
81
89
  proc = -> (name,*args,&blk) {
82
90
  call res.pkg, res.cache, res.elem[:scope][name], *args, &blk
83
91
  }
84
92
 
85
- yield ServiceContext.new(proc,res.elem[:scope].keys), res.elem[:block]
93
+ context_class = Alki::ClassBuilder.build(
94
+ super_class: ValueContext,
95
+ instance_methods: {
96
+ __call__: { body: (blk || res.elem[:block])}
97
+ }
98
+ )
99
+
100
+ yield context_class.new(proc, res.elem[:scope].keys)
86
101
  end
87
102
 
88
103
  class Context
@@ -104,7 +119,7 @@ module Alki
104
119
  end
105
120
  end
106
121
 
107
- class ServiceContext < Context
122
+ class ValueContext < Context
108
123
  def lookup(path)
109
124
  unless path.is_a?(String) or path.is_a?(Symbol)
110
125
  raise ArgumentError.new("lookup can only take Strings or Symbols")
@@ -1,9 +1,9 @@
1
1
  Alki do
2
2
  require_dsl 'alki/dsls/class'
3
3
  require_dsl 'alki/dsls/assembly_types/group'
4
- require_dsl 'alki/dsls/assembly_types/load'
5
- require_dsl 'alki/dsls/assembly_types/service'
4
+ require_dsl 'alki/dsls/assembly_types/value'
6
5
  require_dsl 'alki/dsls/assembly_types/assembly'
6
+ require_dsl 'alki/dsls/assembly_types/load'
7
7
  require_dsl 'alki/dsls/assembly_types/overlay'
8
8
 
9
9
  init do
@@ -2,11 +2,10 @@ require 'alki/support'
2
2
 
3
3
  Alki do
4
4
  dsl_method :load do |group_name,name=group_name.to_s|
5
- add_load group_name, ctx[:prefix], name
5
+ add_load group_name, name
6
6
  end
7
7
 
8
8
  element_type :load do
9
- attr :prefix
10
9
  attr :name
11
10
 
12
11
  index do
@@ -19,17 +18,12 @@ Alki do
19
18
 
20
19
  def group
21
20
  unless (data[:loaded]||={})[name]
22
- if data[:load_path]
23
- require File.join(data[:load_path],name)
24
- else
25
- require name
26
- end
27
- prefixed_name = if prefix
28
- File.join(prefix,name)
21
+ path = if data[:load_path]
22
+ File.join(data[:load_path],"#{name}.rb")
29
23
  else
30
24
  name
31
25
  end
32
- data[:loaded][name] = Alki::Support.load_class(prefixed_name).root
26
+ data[:loaded][name] = Alki::Dsl.load(path)[:class].root
33
27
  end
34
28
  data[:loaded][name]
35
29
  end
@@ -0,0 +1,54 @@
1
+ Alki do
2
+ dsl_method :set do |name,value=nil,&blk|
3
+ add_value name, false, -> (evaluator) {
4
+ val = if blk
5
+ evaluator.call blk
6
+ else
7
+ value
8
+ end
9
+ -> { val }
10
+ }
11
+ end
12
+
13
+ dsl_method :service do |name,&blk|
14
+ add_value name, true, -> (evaluator) {
15
+ svc = evaluator.call blk
16
+ -> { svc }
17
+ }
18
+ end
19
+
20
+ dsl_method :factory do |name,&blk|
21
+ add_value name, false, -> (evaluator) {
22
+ factory = evaluator.call blk
23
+ -> (*args,&blk) {
24
+ factory.call *args, &blk
25
+ }
26
+ }
27
+ end
28
+
29
+ dsl_method :func do |name,&value_blk|
30
+ add_value name, false, -> (evaluator) {
31
+ -> (*args,&blk) {
32
+ evaluator.call(value_blk,*args,&blk)
33
+ }
34
+ }
35
+ end
36
+
37
+ element_type :value do
38
+ attr :apply_overlays
39
+ attr :block
40
+
41
+ output do
42
+ result = {
43
+ type: :value,
44
+ block: block,
45
+ scope: data[:scope].merge(root: [])
46
+ }
47
+ if apply_overlays
48
+ last_clear = data[:overlays].rindex(:clear)
49
+ result[:overlays] = last_clear ? data[:overlays][(last_clear + 1)..-1] : data[:overlays]
50
+ end
51
+ result
52
+ end
53
+ end
54
+ end
data/lib/alki/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Alki
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/alki.rb CHANGED
@@ -1,39 +1,12 @@
1
- require 'alki/support'
2
- require 'alki/assembly'
3
- require 'alki/class_builder'
4
- require 'alki/dsl'
1
+ require 'alki/assembly_builder'
5
2
 
6
3
  module Alki
7
- def self.create_assembly!(name=nil,root=nil)
8
- if !root
9
- root = Alki::Support.find_root(caller_locations(1, 1)[0].absolute_path) do |dir|
10
- File.exists?(File.join(dir,'config','assembly.rb'))
11
- end
12
- end
13
- if !name
14
- path = caller_locations(1,1)[0].absolute_path
15
- lib_dir = File.join(root,'lib','')
16
- unless path.start_with?(lib_dir) && path.end_with?('.rb')
17
- raise "Can't auto-detect name of assembly"
18
- end
19
- name = path[lib_dir.size..-4]
20
- end
21
- config_root = File.join(root,'config')
22
- Alki::ClassBuilder.build(
23
- name: name,
24
- class_modules: [Alki::Assembly],
25
- type: :module,
26
- class_methods: {
27
- assembly_class: {
28
- body: ->{
29
- @assembly_class ||= Alki::Dsl.load(File.join(config_root,'assembly.rb'))[:class]
30
- }
31
- },
32
- config_root: {
33
- body: ->{ config_root }
34
- }
35
- }
36
- )
37
- Alki::Dsl.register_dir config_root, 'alki/dsls/assembly', prefix: File.join(name,'assembly')
4
+ def self.create_assembly!(opts={},&blk)
5
+ opts[:path] ||= caller_locations(1,1)[0].absolute_path
6
+ AssemblyBuilder.build(opts,&blk)
7
+ end
8
+
9
+ def self.create_assembly(opts={},&blk)
10
+ AssemblyBuilder.build(opts,&blk)
38
11
  end
39
12
  end
@@ -0,0 +1,59 @@
1
+ require_relative '../test_helper'
2
+ require 'alki'
3
+
4
+ describe Alki do
5
+ describe :create_assembly do
6
+ def build(opts={},&blk)
7
+ Alki.create_assembly opts, &blk
8
+ end
9
+
10
+ it 'should return module with ::assembly, ::root, and ::new methods' do
11
+ klass = build
12
+ klass.must_respond_to :assembly
13
+ klass.must_respond_to :root
14
+ klass.must_respond_to :new
15
+ end
16
+
17
+ it 'should use provided block to provide assembly definition' do
18
+ klass = build do
19
+ service :svc do
20
+ :val1
21
+ end
22
+ end
23
+ klass.new.svc.must_equal :val1
24
+ end
25
+
26
+ it 'should load assembly definition from config_dir if provided' do
27
+ build(config_dir: fixture_path('tlogger','config')).new.must_respond_to :log
28
+ end
29
+
30
+ it 'should load file other than assembly if provided with primary_config' do
31
+ build(
32
+ config_dir: fixture_path('example','config'),
33
+ primary_config: 'settings'
34
+ ).new.must_respond_to :fizz
35
+ end
36
+
37
+ it 'should create class if provided with a name' do
38
+ klass = build(name: 'alki_test/test_assembly')
39
+ AlkiTest::TestAssembly.must_equal klass
40
+ Object.send :remove_const, :AlkiTest
41
+ end
42
+
43
+ it 'should automatically determine config_dir and name if path provided' do
44
+ was_defined = defined? Tlogger
45
+ Object.send :remove_const, :Tlogger if was_defined
46
+ klass = build(path: fixture_path('tlogger','lib','tlogger.rb'))
47
+ Tlogger.must_equal klass
48
+ klass.new.must_respond_to :log
49
+ Object.send :remove_const, :Tlogger unless was_defined
50
+ end
51
+ end
52
+
53
+ describe :create_assembly! do
54
+ it 'should automatically set path option using path of caller' do
55
+ require fixture_path('tlogger','lib','tlogger.rb')
56
+ Tlogger.new.must_respond_to :log
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../test_helper'
2
+
3
+
4
+ $LOAD_PATH.unshift Alki::Test.fixture_path('example','lib')
5
+ $LOAD_PATH.unshift Alki::Test.fixture_path('tlogger','lib')
6
+
7
+ describe 'Example' do
8
+ before do
9
+ require 'example'
10
+
11
+ @expected = [
12
+ "1","2","Fizz!","4","Buzz!","Fizz!","7", "8", "Fizz!",
13
+ "Buzz!", "11", "Fizz!", "13", "14", "Fizzbuzz!", "16",
14
+ "17", "Fizz!", "19", "Buzz!"
15
+ ]
16
+ @handlers = [
17
+ ['fizzbuzz', /Fizzbuzz!/],
18
+ ['fizz', /Fizz!/],
19
+ ['buzz', /Buzz!/],
20
+ ['echo', /\d+/],
21
+ ]
22
+ end
23
+
24
+ describe 'run' do
25
+ before do
26
+ @app = Example.new
27
+ @app.run 1..20
28
+ end
29
+
30
+ it 'should set output to correct fizzbuzz results' do
31
+ @app.output.to_a.must_equal @expected
32
+ end
33
+
34
+ it 'should log calls to handlers due to overlay' do
35
+ log_lines = @app.log_io.string.split(/\n/)
36
+
37
+ @expected.each.with_index do |val,i|
38
+ @handlers.find do |(handler,re)|
39
+ log_lines.shift.must_equal "Calling handlers.#{handler}#handle #{i+1}"
40
+ val =~ re
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -12,6 +12,10 @@ Alki do
12
12
  ]
13
13
  end
14
14
 
15
+ func :run do |range|
16
+ range_handler.handle range
17
+ end
18
+
15
19
  service :range_handler do
16
20
  require 'range_handler'
17
21
  RangeHandler.new lazy('handler')
@@ -22,8 +26,15 @@ Alki do
22
26
  ArrayOutput.new
23
27
  end
24
28
 
29
+ service :log_io do
30
+ require 'stringio'
31
+ StringIO.new
32
+ end
33
+
25
34
  assembly :tlogger do
26
- set :io, STDERR
35
+ set :io do
36
+ log_io
37
+ end
27
38
  end
28
39
 
29
40
  service :log do
@@ -25,6 +25,6 @@ Alki do
25
25
 
26
26
  overlay do
27
27
  require 'log_overlay'
28
- LogOverlay.new lazy('log')
28
+ LogOverlay.new lookup('log')
29
29
  end
30
30
  end
@@ -1,6 +1,5 @@
1
1
  require_relative '../../test_helper'
2
2
  require 'alki/dsls/assembly'
3
- require 'alki/assembly_processor'
4
3
 
5
4
  describe Alki::Dsls::Assembly do
6
5
  it 'should work' do
@@ -17,12 +16,10 @@ describe Alki::Dsls::Assembly do
17
16
  end
18
17
  end
19
18
  end
20
- p res[:class].assembly
21
- res[:class].assembly.children[:file].name.must_equal 'file'
22
- res[:class].assembly.children[:test].block.call.must_equal :val
23
- res[:class].assembly.children[:group1].children[:test2].block.call.must_equal :val2
19
+ res[:class].root.children[:file].name.must_equal 'file'
20
+ res[:class].root.children[:test].must_respond_to :block
21
+ res[:class].root.children[:group1].children[:test2].must_respond_to :block
24
22
 
25
- r = res[:class].assembly.lookup [:group1,:test2]
26
- p r
23
+ r = res[:class].root.lookup [:group1,:test2]
27
24
  end
28
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
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-11-30 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,28 +64,28 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.2'
67
+ version: '0.3'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0.2'
74
+ version: '0.3'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: alki-support
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0.4'
81
+ version: '0.5'
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0.4'
88
+ version: '0.5'
89
89
  description: Base library for building applications. Provides tools for organizing
90
90
  and connecting application units.
91
91
  email:
@@ -103,6 +103,7 @@ files:
103
103
  - config/dsls.rb
104
104
  - lib/alki.rb
105
105
  - lib/alki/assembly.rb
106
+ - lib/alki/assembly_builder.rb
106
107
  - lib/alki/assembly_executor.rb
107
108
  - lib/alki/assembly_handler_base.rb
108
109
  - lib/alki/dsls/assembly.rb
@@ -112,13 +113,14 @@ files:
112
113
  - lib/alki/dsls/assembly_types/group.rb
113
114
  - lib/alki/dsls/assembly_types/load.rb
114
115
  - lib/alki/dsls/assembly_types/overlay.rb
115
- - lib/alki/dsls/assembly_types/service.rb
116
+ - lib/alki/dsls/assembly_types/value.rb
116
117
  - lib/alki/dsls/service.rb
117
118
  - lib/alki/overlay_delegator.rb
118
119
  - lib/alki/service_delegator.rb
119
120
  - lib/alki/test.rb
120
121
  - lib/alki/version.rb
121
- - test/feature/create_package_test.rb
122
+ - test/feature/alki_test.rb
123
+ - test/feature/example_test.rb
122
124
  - test/fixtures/config.rb
123
125
  - test/fixtures/example/config/assembly.rb
124
126
  - test/fixtures/example/config/handlers.rb
@@ -161,7 +163,8 @@ signing_key:
161
163
  specification_version: 4
162
164
  summary: Base library for building applications.
163
165
  test_files:
164
- - test/feature/create_package_test.rb
166
+ - test/feature/alki_test.rb
167
+ - test/feature/example_test.rb
165
168
  - test/fixtures/config.rb
166
169
  - test/fixtures/example/config/assembly.rb
167
170
  - test/fixtures/example/config/handlers.rb
@@ -1,25 +0,0 @@
1
- Alki do
2
- dsl_method :set do |name,value=nil,&blk|
3
- add_service name, :service, (blk || -> { value })
4
- end
5
-
6
- dsl_method :service do |name,&blk|
7
- add_service name, :service, blk
8
- end
9
-
10
- dsl_method :factory do |name,&blk|
11
- add_service name, :factory, blk
12
- end
13
-
14
- element_type :service do
15
- attr :type
16
- attr :block
17
-
18
- output do
19
- last_clear = data[:overlays].rindex(:clear)
20
- overlays = last_clear ? data[:overlays][(last_clear + 1)..-1] : data[:overlays]
21
- scope = data[:scope].merge root: []
22
- {type: type, block: block, overlays: overlays, scope: scope}
23
- end
24
- end
25
- end
@@ -1,18 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- describe 'Alki.create_package!' do
4
- describe 'example' do
5
- it 'should do fizzbuzz' do
6
- $LOAD_PATH << File.join(fixtures_path,'example','lib')
7
- $LOAD_PATH << File.join(fixtures_path,'tlogger','lib')
8
- require 'example'
9
- app = Example.new
10
- app.range_handler.handle 1..20
11
- app.output.to_a.must_equal [
12
- "1","2","Fizz!","4","Buzz!","Fizz!","7", "8", "Fizz!",
13
- "Buzz!", "11", "Fizz!", "13", "14", "Fizzbuzz!", "16",
14
- "17", "Fizz!", "19", "Buzz!"
15
- ]
16
- end
17
- end
18
- end