power_stencil 0.4.18 → 0.4.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80af1c57689a2ba89246da59fb373577dd48a31b
4
- data.tar.gz: 1c91918d21e15a9730929db9d58309b415c6098d
3
+ metadata.gz: e2582b92f3e64dba5535548383200c900db71ea5
4
+ data.tar.gz: 52cd784e7160cf2d580c86a06999e6bab6c8b0d1
5
5
  SHA512:
6
- metadata.gz: f4ee7f37502473381418bc6184c6436f5ab05d159ed819d4bfbd4cc39554130cddd9a2d0742db82db7f7103738d7b7614df3cd1753e0d29a9713fc98608d5999
7
- data.tar.gz: bd212747f02e36cc2d3d93f37246152c34ba7552af969757cada09122063ca1633e05b47a549abd9d703bb7bff3e9a8f8bc380f53b767475b0477cc4a745e5e5
6
+ metadata.gz: 8df322c9851a1126691cea6a7c9b2fb66dad309845b63073625ad392319c0d9221eb98f73401a5cbfe4b04bfd654d87c9dc83e281477317b82071938f33bb802
7
+ data.tar.gz: 3a141b9153a9d25ef54eaa8a581b64585961a9954508f8cd75631c399e7f73914af2d4e0f1b673ae16c4a7728f033b924210a28d4d3065ea64d25744439c5246
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
 
@@ -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 it would be very weird to do that during the process of detemplating !
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
 
@@ -189,6 +189,13 @@
189
189
  :options:
190
190
  regexp:
191
191
  <<: *REGEXPOPT
192
+ invalid-only:
193
+ :type: boolean
194
+ :summary: Show invalid entities only.
195
+ :long_aliases:
196
+ - invalid
197
+ :short_aliases:
198
+ - i
192
199
  create:
193
200
  :banner: |
194
201
  Creates entities in the repository.
@@ -201,7 +208,7 @@
201
208
  :options:
202
209
  property:
203
210
  :type: array
204
- :summary: Specifiies a first-level property for the entity
211
+ :summary: Specifies a first-level property for the entity
205
212
  :short_aliases:
206
213
  - p
207
214
  edit:
@@ -230,7 +237,7 @@
230
237
 
231
238
  Usage:
232
239
 
233
- edit [object_type[[/ ]object_name]] [options]
240
+ edit [entity_type[[/ ]entity_name]] [options]
234
241
 
235
242
  Edits repository entities. Parameters are used the same way as in 'get'.
236
243
  :options:
@@ -246,7 +253,7 @@
246
253
 
247
254
  Usage:
248
255
 
249
- delete [object_type[[/ ]object_name]] [options]
256
+ delete [entity_type[[/ ]entity_name]] [options]
250
257
 
251
258
  Deletes repository entities. Parameters are used the same way as in 'get'.
252
259
  :options:
@@ -254,6 +261,16 @@
254
261
  delete-files:
255
262
  :type: bool
256
263
  :summary: Will also remove files related to the entity.
264
+ describe:
265
+ :banner: |
266
+ Detailed information about entity types.
267
+
268
+ Usage:
269
+
270
+ describe [entity_type]* [options]
271
+
272
+ Displays information about core properties of given entity types.
273
+ By default will describe all entity types.
257
274
  build:
258
275
  :banner: |
259
276
  Builds entities.
@@ -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
@@ -9,23 +9,25 @@ module PowerStencil
9
9
  include PowerStencil::CommandProcessors::EntityHelper
10
10
 
11
11
  def execute
12
- puts 'RAW ENTITIES'
13
12
  targets = targets_from_criteria analyse_extra_params, project.engine.root_universe
14
- targets.sort {|a,b| a.as_path <=> b.as_path }
15
- .map do |entity|
13
+ sorted_targets = targets.sort {|a,b| a.as_path <=> b.as_path }
14
+ if config[:'invalid-only']
15
+ sorted_targets.reject! &:valid?
16
+ if sorted_targets.empty?
17
+ puts 'No invalid entity found in this repository.'
18
+ return
19
+ else
20
+ puts 'Showing invalid entities only:'
21
+ end
22
+ end
23
+ sorted_targets.map do |entity|
16
24
  entity_info = [" '#{entity.as_path}':"]
17
25
  entity_info << " - Storage path : '#{entity.source_uri}'"
18
26
  entity_info << " - Templates path : '#{entity.templates_path}'" if entity.respond_to? :templates_path
19
27
  entity_info << " - Status : #{entity.valid? ? 'Valid' : 'INVALID !'} "
20
28
  entity_info << " - Buildable : #{entity.buildable?}"
21
29
  entity_info
22
- end .each { |l| puts l }
23
-
24
-
25
- #
26
- # targets.map do |entity|
27
- # " - '#{entity.as_path}': '#{entity.source_uri}'"
28
- # end .sort.each { |l| puts l }
30
+ end .each { |entity_info| puts entity_info }
29
31
  end
30
32
 
31
33
 
@@ -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
- raise PowerStencil::Error, msg
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
@@ -1,3 +1,3 @@
1
1
  module PowerStencil
2
- VERSION = '0.4.18'.freeze
2
+ VERSION = '0.4.20'.freeze
3
3
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_dependency 'climatic', '~> 0.2.29'
29
29
  spec.add_dependency 'dir_glob_ignore', '~> 0.3'
30
- spec.add_dependency 'universe_compiler', '~> 0.4.3'
30
+ spec.add_dependency 'universe_compiler', '~> 0.5.1'
31
31
  spec.add_dependency 'pry'
32
32
 
33
33
  source_code_uri = 'https://gitlab.com/tools4devops/power_stencil'
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.18
4
+ version: 0.4.20
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-04 00:00:00.000000000 Z
11
+ date: 2019-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.4.3
89
+ version: 0.5.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.4.3
96
+ version: 0.5.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -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.18 !\nFrom the
264
+ post_install_message: "\nThank you for installing PowerStencil 0.4.20 !\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 :