power_stencil 0.4.18 → 0.4.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/doc/templates.md +28 -2
- data/etc/base_commands_definition.yml +13 -3
- data/lib/power_stencil.rb +1 -0
- data/lib/power_stencil/command_processors/describe.rb +19 -0
- data/lib/power_stencil/command_processors/entity_helper.rb +85 -0
- data/lib/power_stencil/initializer.rb +2 -1
- data/lib/power_stencil/project/versioning.rb +5 -1
- data/lib/power_stencil/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e3d1927e39aa8060f7d38ce99b83f28ff6ef4aa
|
4
|
+
data.tar.gz: 9cfd4aeae7c9dbca4ebd76f51d61089df0521f68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2168d96b8d1a52ebc324b7931b59d712d364e3e352a7fd573743cb718fb835b88d92926172c9aca316e0743436c04eba1c6cb032914c8fced3a702ed4cc23cc3
|
7
|
+
data.tar.gz: b729958fc82e4dddc9f7180ca3198aabf32bc1475c61ad4258674db055d2df1af8b7c1432a9e34c79560419ca1137ab53c8b853e0a4e10cac8e5847766da08a1
|
data/README.md
CHANGED
@@ -119,6 +119,7 @@ PowerStencil is the Swiss-army knife templating workflow for developers and ops.
|
|
119
119
|
* create: Creates entities in the repository ...
|
120
120
|
* edit: Edit entities from repository ...
|
121
121
|
* delete: Delete entities from repository ...
|
122
|
+
* describe: Detailed information about entity types ...
|
122
123
|
* build: Builds entities ...
|
123
124
|
```
|
124
125
|
|
data/doc/templates.md
CHANGED
@@ -146,7 +146,32 @@ Here are the main methods:
|
|
146
146
|
- `build_target` will return the entity that you are currently building.
|
147
147
|
- `project_config` is a shortcut to the project entity. You could actually retrieve it using the `entity(:project_config, 'Project Config')` method.
|
148
148
|
|
149
|
-
And of course you have access like in `power_stencil shell` to any class brought by `PowerStencil`, you could create entities there, destroy some, **but you should not do it**, as
|
149
|
+
And of course you have access like in `power_stencil shell` to any class brought by `PowerStencil`, you could create entities there, destroy some, **but you should not do it**, as doing this during the process of detemplating could lead to strange behaviours !
|
150
|
+
|
151
|
+
Nevertheless you can of course use entities data and methods within your templates. Any data can be directly accessed using [entity field] mechanism. But entities may bring as well methods you may want to use within your templates. How can we know what can be done with an entity **without reading the code** ? The answer is `power_stencil describe`...
|
152
|
+
|
153
|
+
:information_source: If you do `power_stencil describe` on any entity type, you will get a comprehensive report of what you can do with this or this entity type (by default all entity types are displayed).
|
154
|
+
|
155
|
+
Here is a (not so interesting) example:
|
156
|
+
|
157
|
+
```
|
158
|
+
$ power_stencil describe simple_exec
|
159
|
+
--------------------------------------------------------------------------------
|
160
|
+
=> simple_exec (class: PowerStencil::SystemEntityDefinitions::SimpleExec)
|
161
|
+
- PARENT ENTITY TYPE: base_entity
|
162
|
+
- FIELDS:
|
163
|
+
- description
|
164
|
+
- post_process:
|
165
|
+
- has_one: process_descriptor
|
166
|
+
- not_null: true
|
167
|
+
- METHODS:
|
168
|
+
- delete
|
169
|
+
- valid?
|
170
|
+
- save
|
171
|
+
```
|
172
|
+
|
173
|
+
This should be self explanatory, there is another part that could be displayed in case you defined complex relation using the [reverse methods] mechanism...
|
174
|
+
|
150
175
|
|
151
176
|
# Where do I create templates ?
|
152
177
|
|
@@ -324,7 +349,8 @@ Flawless victory !!
|
|
324
349
|
[plugins]: plugins.md "Plugins in PowerStencil"
|
325
350
|
[example use cases]: example_use_cases.md "Example uses cases using PowerStencil"
|
326
351
|
[buildable]: entities.md#buildable-and-buildable_by "How to make an entity buildable ?"
|
327
|
-
|
352
|
+
[entity field]: entities.md#field "How to access basic entity data"
|
353
|
+
[reverse methods]: entities.md#has_one "Check reverse methods"
|
328
354
|
<!-- Code links -->
|
329
355
|
|
330
356
|
|
@@ -201,7 +201,7 @@
|
|
201
201
|
:options:
|
202
202
|
property:
|
203
203
|
:type: array
|
204
|
-
:summary:
|
204
|
+
:summary: Specifies a first-level property for the entity
|
205
205
|
:short_aliases:
|
206
206
|
- p
|
207
207
|
edit:
|
@@ -230,7 +230,7 @@
|
|
230
230
|
|
231
231
|
Usage:
|
232
232
|
|
233
|
-
edit [
|
233
|
+
edit [entity_type[[/ ]entity_name]] [options]
|
234
234
|
|
235
235
|
Edits repository entities. Parameters are used the same way as in 'get'.
|
236
236
|
:options:
|
@@ -246,7 +246,7 @@
|
|
246
246
|
|
247
247
|
Usage:
|
248
248
|
|
249
|
-
delete [
|
249
|
+
delete [entity_type[[/ ]entity_name]] [options]
|
250
250
|
|
251
251
|
Deletes repository entities. Parameters are used the same way as in 'get'.
|
252
252
|
:options:
|
@@ -254,6 +254,16 @@
|
|
254
254
|
delete-files:
|
255
255
|
:type: bool
|
256
256
|
:summary: Will also remove files related to the entity.
|
257
|
+
describe:
|
258
|
+
:banner: |
|
259
|
+
Detailed information about entity types.
|
260
|
+
|
261
|
+
Usage:
|
262
|
+
|
263
|
+
describe [entity_type]* [options]
|
264
|
+
|
265
|
+
Displays information about core properties of given entity types.
|
266
|
+
By default will describe all entity types.
|
257
267
|
build:
|
258
268
|
:banner: |
|
259
269
|
Builds entities.
|
data/lib/power_stencil.rb
CHANGED
@@ -32,6 +32,7 @@ require 'power_stencil/command_processors/delete'
|
|
32
32
|
require 'power_stencil/command_processors/shell'
|
33
33
|
require 'power_stencil/command_processors/plugin'
|
34
34
|
require 'power_stencil/command_processors/build'
|
35
|
+
require 'power_stencil/command_processors/describe'
|
35
36
|
|
36
37
|
|
37
38
|
module PowerStencil
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PowerStencil
|
2
|
+
module CommandProcessors
|
3
|
+
|
4
|
+
class Describe
|
5
|
+
|
6
|
+
include Climatic::Script::UnimplementedProcessor
|
7
|
+
include Climatic::Proxy
|
8
|
+
include PowerStencil::Project::Proxy
|
9
|
+
include PowerStencil::CommandProcessors::EntityHelper
|
10
|
+
|
11
|
+
def execute
|
12
|
+
targets = extra_params_to_entity_types
|
13
|
+
describe_entity_types targets
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -9,6 +9,49 @@ module PowerStencil
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
def describe_entity_types(entity_types)
|
13
|
+
report = {}
|
14
|
+
project.engine.available_entity_types.each { |entity_type| report = build_entity_type_report entity_type, report }
|
15
|
+
scoped_classes = report.keys
|
16
|
+
|
17
|
+
report.select{|klass, _| entity_types.include? klass.entity_type}
|
18
|
+
.sort_by {|klass, _| klass.entity_type.to_s}
|
19
|
+
.each do |klass, info|
|
20
|
+
puts '-' * 80
|
21
|
+
puts "=> #{klass.entity_type} (class: #{klass.name})"
|
22
|
+
puts " - PARENT ENTITY TYPE: #{klass.superclass.entity_type}" if scoped_classes.include? klass.superclass
|
23
|
+
unless info[:fields].empty?
|
24
|
+
puts ' - FIELDS:'
|
25
|
+
info[:fields].each do |field_name, constraints|
|
26
|
+
if constraints.empty?
|
27
|
+
puts " - #{field_name}"
|
28
|
+
else
|
29
|
+
puts " - #{field_name}:"
|
30
|
+
constraints.each do |name, value|
|
31
|
+
puts " - #{name}: #{value}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
unless info[:methods].empty?
|
37
|
+
puts ' - METHODS:'
|
38
|
+
info[:methods].each do |method_name, _|
|
39
|
+
puts " - #{method_name}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
unless info[:special_methods].empty?
|
43
|
+
puts ' - SPECIAL METHODS:'
|
44
|
+
info[:special_methods].each do |method_name, method_info|
|
45
|
+
puts " - #{method_name} (reverse method defined from relation '#{method_info[:source_field]}' in entity type '#{method_info[:source_entity]}')"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
12
55
|
def display_entity(entity)
|
13
56
|
puts_and_logs "# Entity '#{entity.name}' (#{entity.type})"
|
14
57
|
if config[:'names-only']
|
@@ -66,6 +109,20 @@ module PowerStencil
|
|
66
109
|
end
|
67
110
|
end
|
68
111
|
|
112
|
+
def extra_params_to_entity_types(params = config.command_line_layer.extra_parameters)
|
113
|
+
known_entity_types = project.engine.available_entity_types
|
114
|
+
return known_entity_types if params.empty?
|
115
|
+
|
116
|
+
params.map do |possible_entity_type|
|
117
|
+
possible_entity_type = possible_entity_type.to_sym
|
118
|
+
raise PowerStencil::Error, "Invalid entity type '#{possible_entity_type}' !" unless known_entity_types.include? possible_entity_type
|
119
|
+
possible_entity_type
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
69
126
|
def extra_params_to_entity_search_criteria(params)
|
70
127
|
criteria = []
|
71
128
|
next_entity_reference = EntitySearchReference.new
|
@@ -101,6 +158,34 @@ module PowerStencil
|
|
101
158
|
private
|
102
159
|
|
103
160
|
|
161
|
+
def build_entity_type_report(entity_type, report = {})
|
162
|
+
klass = project.engine.available_entities_hash[entity_type]
|
163
|
+
report[klass] ||= {fields: {}, methods: {}, special_methods: {}}
|
164
|
+
entity_type_info = report[klass]
|
165
|
+
|
166
|
+
# Fields
|
167
|
+
klass.fields_constraints.each do |field_name, constraints|
|
168
|
+
next if constraints[:reverse_method]
|
169
|
+
entity_type_info[:fields][field_name] = {}
|
170
|
+
constraints.each do |constraint_name, constraints_value|
|
171
|
+
entity_type_info[:fields][field_name][constraint_name] = constraints_value
|
172
|
+
end
|
173
|
+
end
|
174
|
+
# Methods
|
175
|
+
klass.public_instance_methods(false).select do |method_name|
|
176
|
+
klass.method_defined? method_name
|
177
|
+
end .each do |method_name|
|
178
|
+
entity_type_info[:methods][method_name] = klass
|
179
|
+
end
|
180
|
+
# Special methods
|
181
|
+
klass.fields_constraints.each do |method_name, constraints|
|
182
|
+
next unless constraints[:reverse_method]
|
183
|
+
entity_type_info[:special_methods][method_name] = constraints[:reverse_method]
|
184
|
+
end
|
185
|
+
|
186
|
+
report
|
187
|
+
end
|
188
|
+
|
104
189
|
def analyse_extra_params(extra_params = config.command_line_layer.extra_parameters, default: [''])
|
105
190
|
params_to_check = if extra_params.empty? then
|
106
191
|
config[:regexp] = true
|
@@ -48,7 +48,8 @@ module PowerStencil
|
|
48
48
|
delete: PowerStencil::CommandProcessors::Delete,
|
49
49
|
shell: PowerStencil::CommandProcessors::Shell,
|
50
50
|
plugin: PowerStencil::CommandProcessors::Plugin,
|
51
|
-
build: PowerStencil::CommandProcessors::Build
|
51
|
+
build: PowerStencil::CommandProcessors::Build,
|
52
|
+
describe: PowerStencil::CommandProcessors::Describe
|
52
53
|
}.each do |command_name, processor|
|
53
54
|
command_line_manager.register_processor command_line_manager.command_by_alias(command_name),
|
54
55
|
processor.new
|
@@ -5,7 +5,11 @@ module PowerStencil
|
|
5
5
|
|
6
6
|
def check_project_version
|
7
7
|
return if project_version_valid?
|
8
|
-
|
8
|
+
msg = <<~EOM
|
9
|
+
This PowerStencil project requires a version of PowerStencil >= #{config[:min_power_stencil_version]} (You are using version #{PowerStencil::VERSION}) !
|
10
|
+
You should consider upgrading by doing 'gem install power_stencil'...
|
11
|
+
EOM
|
12
|
+
raise PowerStencil::Error, msg.chomp
|
9
13
|
end
|
10
14
|
|
11
15
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: power_stencil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent Briais
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- lib/power_stencil/command_processors/check.rb
|
192
192
|
- lib/power_stencil/command_processors/create.rb
|
193
193
|
- lib/power_stencil/command_processors/delete.rb
|
194
|
+
- lib/power_stencil/command_processors/describe.rb
|
194
195
|
- lib/power_stencil/command_processors/edit.rb
|
195
196
|
- lib/power_stencil/command_processors/entity_helper.rb
|
196
197
|
- lib/power_stencil/command_processors/get.rb
|
@@ -260,7 +261,7 @@ metadata:
|
|
260
261
|
documentation_uri: https://gitlab.com/tools4devops/power_stencil/blob/master/README.md
|
261
262
|
source_code_uri: https://gitlab.com/tools4devops/power_stencil
|
262
263
|
homepage_uri: https://powerstencil.brizone.org/
|
263
|
-
post_install_message: "\nThank you for installing PowerStencil 0.4.
|
264
|
+
post_install_message: "\nThank you for installing PowerStencil 0.4.19 !\nFrom the
|
264
265
|
command line you can run `power_stencil --help`\nIf your shell is not completing
|
265
266
|
the command:\n If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial
|
266
267
|
Website : https://powerstencil.brizone.org/\nFull documentation here :
|