universe_compiler 0.2.16 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -12
- data/lib/universe_compiler/utils/graphviz.rb +83 -0
- data/lib/universe_compiler/version.rb +1 -1
- data/lib/universe_compiler.rb +2 -0
- data/universe_compiler.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74a3ec7f9f7eabc456f265d047bf92492039fd8f
|
4
|
+
data.tar.gz: af3c07e4b7be608ec614de02fa5200a8a305e236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 551eb041d06b5fb15dac1a4ef75574e98a9315c1e27f75c1ea88843ebca171271b1a20a531b84a6fa54cb22e732be3aa94d4ec4f8a5879b06aa964a6cd9b2876
|
7
|
+
data.tar.gz: 06e25e42a45c83d3a7bca5f10b9c12c11ffe7e20de257f0b70b8b086fdef3e258d9a80780821555b3e052cc7a72aebcec2b16e1d90d70117b88d8c30c15526bd
|
data/README.md
CHANGED
@@ -1,4 +1,27 @@
|
|
1
|
-
|
1
|
+
UniverseCompiler
|
2
|
+
================
|
3
|
+
|
4
|
+
<!-- TOC -->
|
5
|
+
|
6
|
+
- [Overview](#overview)
|
7
|
+
- [Installation](#installation)
|
8
|
+
- [Core Concepts](#core-concepts)
|
9
|
+
- [Entities](#entities)
|
10
|
+
- [Overview](#overview-1)
|
11
|
+
- [Special directives](#special-directives)
|
12
|
+
- [Constraints and relationships directives](#constraints-and-relationships-directives)
|
13
|
+
- [Compilation](#compilation)
|
14
|
+
- [Inheritance](#inheritance)
|
15
|
+
- [Overrides](#overrides)
|
16
|
+
- [Generate a graph of entities using `Graphviz`](#generate-a-graph-of-entities-using-graphviz)
|
17
|
+
- [Development](#development)
|
18
|
+
- [Contributing](#contributing)
|
19
|
+
- [License](#license)
|
20
|
+
- [Code of Conduct](#code-of-conduct)
|
21
|
+
|
22
|
+
<!-- /TOC -->
|
23
|
+
|
24
|
+
# Overview
|
2
25
|
|
3
26
|
The goal of this gem is to provide a simple way to manage a consistent highly complex configuration.
|
4
27
|
|
@@ -15,7 +38,7 @@ a yaml persistence engine is available by default in the gem.
|
|
15
38
|
A `universe` can be _compiled_ in order to produce a new `universe` where all constraints and relations defined
|
16
39
|
by these entities have been resolved.
|
17
40
|
|
18
|
-
|
41
|
+
# Installation
|
19
42
|
|
20
43
|
Add this line to your application's Gemfile:
|
21
44
|
|
@@ -32,11 +55,11 @@ Or install it yourself as:
|
|
32
55
|
$ gem install universe_compiler
|
33
56
|
|
34
57
|
|
35
|
-
|
58
|
+
# Core Concepts
|
36
59
|
|
37
|
-
|
60
|
+
## Entities
|
38
61
|
|
39
|
-
|
62
|
+
### Overview
|
40
63
|
|
41
64
|
Any `entity` you will create will basically inherit from `UniverseCompiler::Entity::Base`. This will allow
|
42
65
|
the following kind of code:
|
@@ -229,7 +252,7 @@ end
|
|
229
252
|
# => [{name: :a, compiled: true},{name: :b, compiled: true},{name: :c, compiled: true}]
|
230
253
|
```
|
231
254
|
|
232
|
-
|
255
|
+
## Inheritance
|
233
256
|
|
234
257
|
To be clear, here we talk about __entities (instances) inheritance, NOT classes !__
|
235
258
|
|
@@ -256,7 +279,7 @@ u2.a --extends--> u2.b --extends--> u2.c
|
|
256
279
|
```
|
257
280
|
You can see an example of inheritance in previous paragraph.
|
258
281
|
|
259
|
-
|
282
|
+
## Overrides
|
260
283
|
|
261
284
|
Overrides are actually a special type of entities. They have a special array called `overrides`
|
262
285
|
which contains a list of entities you want to inject content into.
|
@@ -301,18 +324,54 @@ v.get_entities.map &:fields
|
|
301
324
|
You can see there that the compiled version of `b` contains both data coming from the inheritance mechanism
|
302
325
|
as well as those coming from the override...
|
303
326
|
|
304
|
-
|
327
|
+
# Generate a graph of entities using `Graphviz`
|
328
|
+
|
329
|
+
Provides a [Graphviz] graph of relations using the [ruby-graphviz] gem between a set of entities and allows callback mechanisms for the graph customization.
|
330
|
+
|
331
|
+
All you need is to:
|
332
|
+
|
333
|
+
```ruby
|
334
|
+
include UniverseCompiler::Utils::Graphviz
|
335
|
+
```
|
336
|
+
In any class, and then simply call:
|
337
|
+
```ruby
|
338
|
+
graph_entities_to_file(an_array_of_entities, set_of_options, &customization_block)
|
339
|
+
```
|
340
|
+
|
341
|
+
Calls to the `graph_entities_to_file` method returns either the filename of the created file or the graphiz graph object depending on method parameters.
|
342
|
+
|
343
|
+
A block can be passed to the method, it will yield the graph object, and optionnally a bi-directional structure of entities and graphwiz nodes, allowing for complete graph display customization (you may actually completely change the graph, but maybe in this case you may want to actually completely build the graph. It is normally intended to change/customize display attributes there...).
|
344
|
+
|
345
|
+
# Development
|
305
346
|
|
306
347
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
307
348
|
|
308
349
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
309
350
|
|
310
|
-
|
311
|
-
|
312
|
-
Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/lbriais/universe_compiler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
351
|
+
# Contributing
|
313
352
|
|
353
|
+
Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/tools4devops/power_stencil. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
314
354
|
|
315
355
|
## License
|
316
356
|
|
317
|
-
The gem is available as open source under the terms of the [MIT License]
|
357
|
+
The gem is available as open source under the terms of the [MIT License].
|
358
|
+
|
359
|
+
## Code of Conduct
|
360
|
+
|
361
|
+
Everyone interacting in the PowerStencil project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct].
|
362
|
+
|
363
|
+
|
364
|
+
<!-- End of Document -->
|
365
|
+
|
366
|
+
<!-- Pages -->
|
367
|
+
[code of conduct]: CODE_OF_CONDUCT.md
|
368
|
+
|
369
|
+
<!-- Code links -->
|
370
|
+
|
371
|
+
<!-- Illustrations -->
|
318
372
|
|
373
|
+
<!-- External links -->
|
374
|
+
[MIT License]: http://opensource.org/licenses/MIT "The MIT license"
|
375
|
+
[Ruby]: https://www.ruby-lang.org "The powerful Ruby language"
|
376
|
+
[Graphviz]: (https://www.graphviz.org/) "Graph Visualization Software"
|
377
|
+
[ruby-graphviz]: (https://rubygems.org/gems/ruby-graphviz) "Ruby interface to graphviz"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module UniverseCompiler
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
module Graphviz
|
7
|
+
|
8
|
+
def graph_entities_to_file(entities,
|
9
|
+
output_file_name: nil,
|
10
|
+
file_type: :svg,
|
11
|
+
generate_file: true,
|
12
|
+
&block)
|
13
|
+
g = GraphViz.new( :G, :type => :digraph )
|
14
|
+
|
15
|
+
cache = {by_node: {}, by_entity: {}}
|
16
|
+
# Building nodes
|
17
|
+
entities.each do |entity|
|
18
|
+
node = g.add_node entity.as_path
|
19
|
+
if entity.respond_to? :graphviz_label
|
20
|
+
node[:label] = entity.graphviz_label
|
21
|
+
end
|
22
|
+
cache[:by_entity][entity] = node
|
23
|
+
cache[:by_node][node] = entity
|
24
|
+
end
|
25
|
+
|
26
|
+
# Building relations
|
27
|
+
entities.each do |entity|
|
28
|
+
entity.class.fields_constraints.each do |field_name, field_constraints|
|
29
|
+
field_constraints.each do |constraint_name, _|
|
30
|
+
case constraint_name
|
31
|
+
when :has_one
|
32
|
+
target = entity[field_name]
|
33
|
+
g.add_edges cache[:by_entity][entity], cache[:by_entity][target] unless target.nil?
|
34
|
+
when :has_many
|
35
|
+
entity[field_name].each do |target|
|
36
|
+
g.add_edges cache[:by_entity][entity], cache[:by_entity][target]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if block_given?
|
44
|
+
case block.arity
|
45
|
+
when 1
|
46
|
+
yield g
|
47
|
+
when 2
|
48
|
+
yield g, cache
|
49
|
+
else
|
50
|
+
raise UniverseCompiler::Error, 'Wrong arity when calling UniverseCompiler::Utils::Graphviz#graph_entities_to_file'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
file_ext = file_type.to_s
|
55
|
+
file_ext = (file_ext.start_with? '.') ? file_ext : ".#{file_ext}"
|
56
|
+
|
57
|
+
output_file_name = case output_file_name
|
58
|
+
when NilClass
|
59
|
+
file = Tempfile.create ['entities_graph', file_ext]
|
60
|
+
file.close
|
61
|
+
file.path
|
62
|
+
when String
|
63
|
+
if output_file_name.end_with? file_ext
|
64
|
+
output_file_name
|
65
|
+
else
|
66
|
+
"#{output_file_name}#{file_ext}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if generate_file
|
71
|
+
g.output( file_type => output_file_name )
|
72
|
+
UniverseCompiler.logger.debug "Graph file: '#{output_file_name}'"
|
73
|
+
output_file_name
|
74
|
+
else
|
75
|
+
g
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
data/lib/universe_compiler.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'super_stack'
|
2
|
+
require 'graphviz'
|
2
3
|
|
3
4
|
require 'universe_compiler/version'
|
4
5
|
require 'universe_compiler/error'
|
@@ -7,6 +8,7 @@ require 'universe_compiler/utils/error_propagation'
|
|
7
8
|
require 'universe_compiler/utils/array_utils'
|
8
9
|
require 'universe_compiler/utils/deep_traverse'
|
9
10
|
require 'universe_compiler/utils/with_unique_name'
|
11
|
+
require 'universe_compiler/utils/graphviz'
|
10
12
|
|
11
13
|
module UniverseCompiler
|
12
14
|
extend UniverseCompiler::Utils::BasicLogger
|
data/universe_compiler.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: universe_compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent B.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,20 @@ dependencies:
|
|
134
134
|
- - "~>"
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '5.0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: ruby-graphviz
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :runtime
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
137
151
|
description: Provide a way to create objects with complex relationships, inheritance
|
138
152
|
and override mechanisms.
|
139
153
|
email:
|
@@ -188,6 +202,7 @@ files:
|
|
188
202
|
- lib/universe_compiler/utils/basic_logger.rb
|
189
203
|
- lib/universe_compiler/utils/deep_traverse.rb
|
190
204
|
- lib/universe_compiler/utils/error_propagation.rb
|
205
|
+
- lib/universe_compiler/utils/graphviz.rb
|
191
206
|
- lib/universe_compiler/utils/with_unique_name.rb
|
192
207
|
- lib/universe_compiler/version.rb
|
193
208
|
- universe_compiler.gemspec
|