rachinations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +6 -0
  4. data/.travis.yml +8 -0
  5. data/.yardopts +1 -0
  6. data/Gemfile +19 -0
  7. data/Gemfile.lock +93 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +18 -0
  10. data/Rakefile +16 -0
  11. data/lib/rachinations.rb +49 -0
  12. data/lib/rachinations/domain/diagrams/diagram.rb +167 -0
  13. data/lib/rachinations/domain/diagrams/non_deterministic_diagram.rb +16 -0
  14. data/lib/rachinations/domain/diagrams/verbose_diagram.rb +9 -0
  15. data/lib/rachinations/domain/edge_collection.rb +12 -0
  16. data/lib/rachinations/domain/edges/edge.rb +159 -0
  17. data/lib/rachinations/domain/edges/random_edge.rb +4 -0
  18. data/lib/rachinations/domain/exceptions/bad_options.rb +3 -0
  19. data/lib/rachinations/domain/exceptions/no_elements_found.rb +2 -0
  20. data/lib/rachinations/domain/exceptions/no_elements_matching_condition_error.rb +2 -0
  21. data/lib/rachinations/domain/exceptions/no_elements_of_given_type.rb +3 -0
  22. data/lib/rachinations/domain/exceptions/unsupported_type_error.rb +2 -0
  23. data/lib/rachinations/domain/modules/common/hash_init.rb +88 -0
  24. data/lib/rachinations/domain/modules/common/invariant.rb +17 -0
  25. data/lib/rachinations/domain/modules/diagrams/verbose.rb +30 -0
  26. data/lib/rachinations/domain/node_collection.rb +30 -0
  27. data/lib/rachinations/domain/nodes/converter.rb +276 -0
  28. data/lib/rachinations/domain/nodes/gate.rb +6 -0
  29. data/lib/rachinations/domain/nodes/node.rb +166 -0
  30. data/lib/rachinations/domain/nodes/pool.rb +267 -0
  31. data/lib/rachinations/domain/nodes/resourceful_node.rb +96 -0
  32. data/lib/rachinations/domain/nodes/resourceless_node.rb +11 -0
  33. data/lib/rachinations/domain/nodes/sink.rb +17 -0
  34. data/lib/rachinations/domain/nodes/source.rb +161 -0
  35. data/lib/rachinations/domain/nodes/trader.rb +6 -0
  36. data/lib/rachinations/domain/resource_bag.rb +131 -0
  37. data/lib/rachinations/domain/resources/token.rb +51 -0
  38. data/lib/rachinations/domain/strategies/strategy.rb +5 -0
  39. data/lib/rachinations/domain/strategies/valid_types.rb +69 -0
  40. data/lib/rachinations/dsl/dsl.rb +63 -0
  41. data/lib/rachinations/extras/fifo.rb +27 -0
  42. data/lib/rachinations/version.rb +3 -0
  43. data/machinations_diagrams/apenas_bonito.xml +22 -0
  44. data/machinations_diagrams/behavior_converter.xml +53 -0
  45. data/machinations_diagrams/behavior_converter_fim.xml +10 -0
  46. data/machinations_diagrams/canon/README.md +8 -0
  47. data/machinations_diagrams/canon/converters_differences.xml +27 -0
  48. data/machinations_diagrams/canon/converters_differences2.xml +34 -0
  49. data/machinations_diagrams/canon/converters_similarities.xml +63 -0
  50. data/machinations_diagrams/canon/converters_similarities2.xml +21 -0
  51. data/machinations_diagrams/canon/nodes_and_edges_differences.xml +15 -0
  52. data/machinations_diagrams/canon/nodes_and_edges_similarities.xml +20 -0
  53. data/machinations_diagrams/deterministic_example.xml +46 -0
  54. data/machinations_diagrams/economies_of_scale.xml +32 -0
  55. data/machinations_diagrams/feature_ou_bug.xml +5 -0
  56. data/machinations_diagrams/loop_in_trigger.xml +21 -0
  57. data/machinations_diagrams/naficadevendo.xml +12 -0
  58. data/machinations_diagrams/noreporting_equivalent.xml +22 -0
  59. data/machinations_diagrams/pull_all_example.xml +7 -0
  60. data/machinations_diagrams/sketch_of_memory.xml +41 -0
  61. data/machinations_diagrams/software_engineering_process 2.xml +130 -0
  62. data/machinations_diagrams/software_engineering_process v3.xml +168 -0
  63. data/machinations_diagrams/software_engineering_process v4.xml +192 -0
  64. data/machinations_diagrams/software_engineering_process.xml +65 -0
  65. data/machinations_diagrams/software_engineering_process_with_rework_after_test.xml +195 -0
  66. data/machinations_diagrams/startup_marketing.xml +35 -0
  67. data/machinations_diagrams/triggers_allow_multiple_stages_at_same_round.xml +19 -0
  68. data/machinations_diagrams/um_de_cada_vez_vs_todos_de_uma_vez.xml +20 -0
  69. data/rachinations.gemspec +35 -0
  70. data/testing/features/step_definitions/step_definitions.rb +11 -0
  71. data/testing/simulations/modelo1.rb +20 -0
  72. data/testing/simulations/modelo2.rb +49 -0
  73. data/testing/simulations/noreporting.rb +51 -0
  74. data/testing/simulations/sequencial.rb +19 -0
  75. data/testing/simulations/sobonito.rb +28 -0
  76. data/testing/simulations/sobonitowhile.rb +28 -0
  77. data/testing/simulations/whatIwish1.rb +20 -0
  78. data/testing/spec/canon/converter_spec.rb +33 -0
  79. data/testing/spec/canon/pool_spec.rb +68 -0
  80. data/testing/spec/conditions_spec.rb +10 -0
  81. data/testing/spec/converter_spec.rb +223 -0
  82. data/testing/spec/diagram_spec.rb +671 -0
  83. data/testing/spec/edge_spec.rb +256 -0
  84. data/testing/spec/hash_init_spec.rb +59 -0
  85. data/testing/spec/node_spec.rb +31 -0
  86. data/testing/spec/non_deterministic_diagram_spec.rb +112 -0
  87. data/testing/spec/pool_spec.rb +233 -0
  88. data/testing/spec/source_spec.rb +132 -0
  89. data/testing/spec/spec_helper.rb +34 -0
  90. data/testing/spec/xexeo_spec.rb +193 -0
  91. metadata +283 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5bd962b3b335b5820974f83f65110cdb5c322e36
4
+ data.tar.gz: 16bd1cd9a661aaac83f2d0532898da95d60cd587
5
+ SHA512:
6
+ metadata.gz: cb22e2caebc4211a0d323d5ffa4e967fb777c260fa63e4e4a8b51024d57519066e989616f928cc67830539c17cabf29d79918380f9e60050caa71f52e8a24f0e
7
+ data.tar.gz: 0f7bb8b7800dd390de9a51523a5cbc627bb6fdc7c3404be4e66b90e8a321aad756b3b9afadfe778c73f322af57560b3d6fb5c38a357be663b7361ae26f9e10f7
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .bundle
2
+ .idea
3
+ coverage
4
+ testing/coverage
5
+ .yardoc/
6
+ doc/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - "ruby 2.1.1"
4
+ install: bundle install
5
+ branches:
6
+ only:
7
+ - master
8
+ - new_main_loop
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ domain/* domain/*/* domain/*/*/* domain/*/*/*/* dsl/* - README.md
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rachinations.gemspec
4
+ gemspec
5
+
6
+
7
+ # ruby '2.1.1'
8
+ #
9
+ # gem 'rake'
10
+ # gem 'activesupport','3.0.0'
11
+ # gem 'i18n'
12
+ # gem 'minitest'
13
+ # gem 'minitest-reporters'
14
+ # gem 'rspec'
15
+ # gem 'cucumber'
16
+ # gem 'coveralls', require: false
17
+
18
+
19
+
data/Gemfile.lock ADDED
@@ -0,0 +1,93 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rachinations (0.0.1)
5
+ activesupport (= 3.0.0)
6
+ i18n
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (3.0.0)
12
+ ansi (1.4.3)
13
+ builder (3.2.2)
14
+ coveralls (0.7.0)
15
+ multi_json (~> 1.3)
16
+ rest-client
17
+ simplecov (>= 0.7)
18
+ term-ansicolor
19
+ thor
20
+ cucumber (1.3.16)
21
+ builder (>= 2.1.2)
22
+ diff-lcs (>= 1.1.3)
23
+ gherkin (~> 2.12)
24
+ multi_json (>= 1.7.5, < 2.0)
25
+ multi_test (>= 0.1.1)
26
+ diff-lcs (1.2.5)
27
+ docile (1.1.5)
28
+ ffi (1.9.3-x64-mingw32)
29
+ ffi (1.9.3-x86-mingw32)
30
+ gherkin (2.12.2)
31
+ multi_json (~> 1.3)
32
+ gherkin (2.12.2-x86-mingw32)
33
+ multi_json (~> 1.3)
34
+ i18n (0.6.11)
35
+ mime-types (2.3)
36
+ minitest (5.4.0)
37
+ minitest-reporters (1.0.5)
38
+ ansi
39
+ builder
40
+ minitest (>= 5.0)
41
+ ruby-progressbar
42
+ multi_json (1.10.1)
43
+ multi_test (0.1.1)
44
+ netrc (0.7.7)
45
+ rake (10.3.2)
46
+ rest-client (1.7.2)
47
+ mime-types (>= 1.16, < 3.0)
48
+ netrc (~> 0.7)
49
+ rest-client (1.7.2-x64-mingw32)
50
+ ffi (~> 1.9)
51
+ mime-types (>= 1.16, < 3.0)
52
+ netrc (~> 0.7)
53
+ rest-client (1.7.2-x86-mingw32)
54
+ ffi (~> 1.9)
55
+ mime-types (>= 1.16, < 3.0)
56
+ netrc (~> 0.7)
57
+ rspec (3.0.0)
58
+ rspec-core (~> 3.0.0)
59
+ rspec-expectations (~> 3.0.0)
60
+ rspec-mocks (~> 3.0.0)
61
+ rspec-core (3.0.3)
62
+ rspec-support (~> 3.0.0)
63
+ rspec-expectations (3.0.3)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.0.0)
66
+ rspec-mocks (3.0.3)
67
+ rspec-support (~> 3.0.0)
68
+ rspec-support (3.0.3)
69
+ ruby-progressbar (1.5.1)
70
+ simplecov (0.9.0)
71
+ docile (~> 1.1.0)
72
+ multi_json
73
+ simplecov-html (~> 0.8.0)
74
+ simplecov-html (0.8.0)
75
+ term-ansicolor (1.3.0)
76
+ tins (~> 1.0)
77
+ thor (0.19.1)
78
+ tins (1.3.0)
79
+
80
+ PLATFORMS
81
+ ruby
82
+ x64-mingw32
83
+ x86-mingw32
84
+
85
+ DEPENDENCIES
86
+ bundler (~> 1.5)
87
+ coveralls
88
+ cucumber
89
+ minitest
90
+ minitest-reporters
91
+ rachinations!
92
+ rake
93
+ rspec (~> 3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2014 Felipe Almeida
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ rachinations
2
+ ====================
3
+ [![Build Status](https://travis-ci.org/queirozfcom/rachinations.svg?branch=master)](https://travis-ci.org/queirozfcom/rachinations?branch=master)
4
+ [![Code Climate](https://codeclimate.com/github/queirozfcom/rachinations.png)](https://codeclimate.com/github/queirozfcom/rachinations)
5
+ [![Coverage Status](https://coveralls.io/repos/queirozfcom/rachinations/badge.png?branch=master)](https://coveralls.io/r/queirozfcom/rachinations?branch=master)
6
+
7
+ ### Introduction
8
+
9
+ This is a port of Dr. J. Dormans' Machinations framework into Ruby.
10
+
11
+ ### Contents
12
+
13
+ - Classes to model the domain
14
+ - Tests
15
+ - A simple DSL (Domain-specific language) whose objective is to enable anyone to write Machinations diagrams, run them, obtain metrics, compose subdiagrams and so on.
16
+
17
+ ### Usage
18
+ - TODO
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
5
+
6
+ task :default => [:spec]
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.pattern = 'testing/**/*_test.rb'
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new do |t|
13
+ t.rspec_opts= ['--default-path testing/spec','--color']
14
+ end
15
+
16
+
@@ -0,0 +1,49 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rachinations/version'
4
+
5
+
6
+ # A few extra methods
7
+ # to make code read more intuitively.
8
+ class Proc
9
+
10
+ alias_method :accepts?, :call
11
+ alias_method :accept?, :call
12
+
13
+ alias_method :match?, :call
14
+ alias_method :matches?, :call
15
+
16
+ alias_method :match_resource?, :call
17
+ alias_method :matches_resource?, :call
18
+
19
+ end
20
+
21
+ require 'rachinations/extras/fifo'
22
+
23
+ require 'rachinations/domain/diagrams/diagram'
24
+ require 'rachinations/domain/diagrams/verbose_diagram'
25
+ require 'rachinations/dsl/dsl'
26
+ require 'rachinations/domain/strategies/strategy'
27
+ require 'rachinations/domain/strategies/valid_types'
28
+ require 'rachinations/domain/edges/random_edge'
29
+ require 'rachinations/domain/edges/edge'
30
+ require 'rachinations/domain/exceptions/no_elements_of_given_type'
31
+ require 'rachinations/domain/exceptions/unsupported_type_error'
32
+ require 'rachinations/domain/exceptions/bad_options'
33
+ require 'rachinations/domain/exceptions/no_elements_matching_condition_error'
34
+ require 'rachinations/domain/exceptions/no_elements_found'
35
+ require 'rachinations/domain/nodes/node'
36
+ require 'rachinations/domain/nodes/resourceful_node'
37
+ require 'rachinations/domain/nodes/pool'
38
+ require 'rachinations/domain/nodes/source'
39
+ require 'rachinations/domain/nodes/sink'
40
+ require 'rachinations/domain/nodes/gate'
41
+ require 'rachinations/domain/nodes/trader'
42
+ require 'rachinations/domain/nodes/converter'
43
+ require 'rachinations/domain/resources/token'
44
+ require 'rachinations/domain/edge_collection'
45
+ require 'rachinations/domain/node_collection'
46
+ require 'rachinations/domain/resource_bag'
47
+
48
+
49
+ include DSL
@@ -0,0 +1,167 @@
1
+ require_relative '../../domain/modules/common/invariant'
2
+ require_relative '../edge_collection'
3
+ require_relative '../node_collection'
4
+
5
+ class Diagram
6
+
7
+ include Invariant
8
+
9
+ attr_accessor :name, :max_iterations, :nodes, :edges
10
+
11
+ def initialize(name)
12
+ @nodes = NodeCollection.new
13
+ @edges = EdgeCollection.new
14
+ @name = name
15
+ @max_iterations = 999
16
+ end
17
+
18
+ def get_node(name)
19
+
20
+ nodes.each do |node|
21
+ if node.name == name
22
+ return node
23
+ end
24
+ end
25
+
26
+ raise RuntimeError, "Node with name='#{name}' not found."
27
+ end
28
+
29
+ def add_node!(node_klass, params)
30
+
31
+ params.store(:diagram, self)
32
+
33
+ node = node_klass.new(params)
34
+
35
+ nodes.push(node)
36
+
37
+ self
38
+
39
+ end
40
+
41
+ def add_edge!(edge_klass, params)
42
+
43
+ params.store(:diagram, self)
44
+
45
+ #we need to send the actual nodes, not their names
46
+ from = get_node(params.fetch(:from))
47
+ to = get_node(params.fetch(:to))
48
+
49
+ params.store(:from, from)
50
+ params.store(:to, to)
51
+
52
+ edge = edge_klass.new(params)
53
+
54
+ from.attach_edge!(edge)
55
+ to.attach_edge!(edge)
56
+
57
+ edges.push(edge)
58
+
59
+ self
60
+ end
61
+
62
+ def run!(rounds=5)
63
+
64
+ run_while! do |i|
65
+ i<=rounds
66
+ end
67
+
68
+ end
69
+
70
+ # Runs the diagram until given block returns false
71
+ #
72
+ # @yieldparam i [Fixnum] The current round.
73
+ # @yieldreturn [Boolean] True if diagram should keep on running, false if it should stop.
74
+ # @return [Diagram] The diagram itself.
75
+ def run_while!
76
+
77
+ before_run
78
+
79
+ i=1
80
+
81
+ #if given condition block turned false, it's time to stop
82
+ while yield i do
83
+
84
+ break unless sanity_check? i
85
+
86
+ before_round i
87
+
88
+ if i == 1
89
+ # some things are different for the first round, namely nodes with activation = start
90
+ run_first_round!
91
+ else
92
+ run_round!
93
+ end
94
+
95
+ after_round i
96
+ i+=1
97
+ end
98
+
99
+ after_run
100
+
101
+ self
102
+
103
+ end
104
+
105
+ def to_s
106
+ nodes.reduce('') { |carry, n| carry+n.to_s }
107
+ end
108
+
109
+ def sanity_check?(round_no)
110
+ if round_no > @max_iterations
111
+ sanity_check_message
112
+ false
113
+ else
114
+ true
115
+ end
116
+ end
117
+
118
+ def run_first_round!
119
+
120
+ enabled_nodes.select { |n| n.automatic? || n.start? }.shuffle.each { |n| n.trigger! }
121
+
122
+ commit_nodes!
123
+
124
+ end
125
+
126
+ def run_round!
127
+
128
+ enabled_nodes.select { |n| n.automatic? }.shuffle.each { |node| node.trigger! }
129
+
130
+ commit_nodes!
131
+
132
+ end
133
+
134
+ def commit_nodes!
135
+ #only after all nodes have run do we update the actual resources and changes, to be used in the next round.
136
+ nodes.shuffle.each { |n| n.commit! }
137
+ end
138
+
139
+
140
+ def resource_count(klass=nil)
141
+ total=0
142
+ @nodes.each do |n|
143
+ total+=n.resource_count(klass)
144
+ end
145
+ total
146
+ end
147
+
148
+ def enabled_nodes
149
+ nodes.select{|n| n.enabled? }
150
+ end
151
+
152
+ #template method
153
+ def before_round(node_no) end
154
+
155
+ #template method
156
+ def after_round(node_no) end
157
+
158
+ #template method
159
+ def before_run; end
160
+
161
+ #template method
162
+ def after_run; end
163
+
164
+ #template method
165
+ def sanity_check_message; end
166
+
167
+ end
@@ -0,0 +1,16 @@
1
+
2
+ class NonDeterministicDiagram < Diagram
3
+
4
+
5
+ # This version of run_round! triggers only one node
6
+ # per turn.
7
+ def run_round!
8
+
9
+ node = nodes.sample
10
+ node.trigger!
11
+
12
+ nodes.each{ |n| n.commit! }
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,9 @@
1
+ require 'rachinations/domain/modules/diagrams/verbose'
2
+
3
+ class VerboseDiagram < Diagram
4
+
5
+ #useful to see round-to-round changes, to help debugging for instance.
6
+
7
+ include Verbose
8
+
9
+ end