ruote-library 1.0.0 → 1.1.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/lib/ruote-library.rb CHANGED
@@ -51,17 +51,53 @@ module Ruote
51
51
  # be_funny
52
52
  #
53
53
  # In other words: fetch() loads any referenced subprocess that are not
54
- # defined in the original definition. (Notice the missing single-quotes?)
54
+ # defined in the original definition.
55
+ #
56
+ # === Including referenced
57
+ #
58
+ # Image you have thses files:
59
+ # > cat base.radial
60
+ # define base
61
+ # alpha
62
+ # bravo
63
+ # charly
64
+ #
65
+ # > cat extended.radial
66
+ # define extended
67
+ # taste_soup
68
+ # concurrence
69
+ # lib_include base
70
+ #
71
+ # When you fetch extended, you will receive
72
+ #
73
+ # define extended
74
+ # taste_soup
75
+ # concurrence
76
+ # alpha
77
+ # bravo
78
+ # charly
79
+ #
80
+ # === Notice the missing single-quotes?
81
+ # Because the ProcessLibrary turns all files into Radial (even though it
82
+ # already is a Radial) it performs some optimizing
55
83
  #
56
84
  # === Caveat
57
85
  # In order for this to work you must:
58
86
  #
59
87
  # * Name your files like your (sub)processes, including path from @root
60
- # * Use the 'subprocess' expression
88
+ #
89
+ # * Use the 'subprocess' expression
61
90
  # (see: http://ruote.rubyforge.org/exp/subprocess.html)
62
91
  # otherwise the library will not be able to tell the diference between a
63
92
  # participant and a subprocess
64
93
  #
94
+ # * You cannot have a participant called 'lib_include' if you want to use
95
+ # the inclusion mechanism
96
+ #
97
+ # === Note on inclusion
98
+ # 'lib_include' was added as a way to keep the definitions tree simple, it
99
+ # has no other sane use-case
100
+ #
65
101
  # @param [String] name The name of the file to fetch
66
102
  # @return [String] radial process definition (regardless of what was in
67
103
  # the file)
@@ -93,13 +129,21 @@ module Ruote
93
129
  end
94
130
  end
95
131
 
132
+ if radial =~ /lib_include/
133
+ extras = radial.scan(/^(\s+)lib_include (.+)$/).map do |indent, process|
134
+ sub_process = fetch(process, (indent.length / 2) - 1)
135
+ replacement = sub_process.split("\n")[1..-1].join("\n")
136
+ radial.gsub!("#{indent}lib_include #{process}", replacement)
137
+ end
138
+ end
139
+
96
140
  return radial
97
141
  end
98
142
 
99
143
  # Read a process definition from file
100
144
  #
101
145
  # @param [String] name The name of the process - should be the filename,
102
- # the extension is optional and tried in the order .radial, .json and
146
+ # the extension is optional and tried in the order .radial, .json and
103
147
  # finaly .xml
104
148
  #
105
149
  # @return [String] The contents of the first found file
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
12
  gem.name = "ruote-library"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "1.0.0"
14
+ gem.version = "1.1.0"
15
15
 
16
16
  gem.add_dependency 'ruote', ['~> 2.3']
17
17
 
@@ -103,4 +103,19 @@ describe Ruote::ProcessLibrary do
103
103
  )
104
104
  end
105
105
  end
106
+
107
+ describe :inclusion do
108
+ it "includes other processes" do
109
+ pdef = @library.fetch("inclusive/test")
110
+ pdef.should == "define inclusive/test
111
+ foo
112
+ bar
113
+ cursor
114
+ recruit_troops
115
+ train_troops
116
+ rewind unless: \"${f:enough_troops}\"
117
+ build_phalanx_formation
118
+ send_formation direction: forward\n"
119
+ end
120
+ end
106
121
  end
@@ -0,0 +1,7 @@
1
+ define inclusive/test
2
+ foo
3
+ bar
4
+ cursor
5
+ lib_include 'army/build'
6
+ rewind unless: '${f:enough_troops}'
7
+ lib_include army/attack
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruote-library
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-21 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruote
16
- requirement: &16232700 !ruby/object:Gem::Requirement
16
+ requirement: &29558760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16232700
24
+ version_requirements: *29558760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &16232300 !ruby/object:Gem::Requirement
27
+ requirement: &29558060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *16232300
35
+ version_requirements: *29558060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mocha
38
- requirement: &14938560 !ruby/object:Gem::Requirement
38
+ requirement: &29557080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *14938560
46
+ version_requirements: *29557080
47
47
  description: A library for Ruote processes, based on FS storage and sub-processes
48
48
  email:
49
49
  - hartog@organisedminds.com
@@ -65,6 +65,7 @@ files:
65
65
  - spec/support/processes/army/build.radial
66
66
  - spec/support/processes/country/attack.radial
67
67
  - spec/support/processes/defined.radial
68
+ - spec/support/processes/inclusive/test.radial
68
69
  - spec/support/processes/json.json
69
70
  - spec/support/processes/recursive.radial
70
71
  - spec/support/processes/subs.radial