...
 
Commits (5)
......@@ -21,6 +21,7 @@ require 'power_stencil/utils/gem_utils'
require 'power_stencil/utils/file_edit'
require 'power_stencil/utils/graphviz'
require 'power_stencil/utils/completion'
require 'power_stencil/utils/entity_helper'
require 'climatic/script/unimplemented_processor'
require 'power_stencil/project/proxy'
......
......@@ -19,15 +19,19 @@ module PowerStencil
if md = property_def.match(/^\s*(?<prop_name>[^:=]+)\s*[:=]\s*(?<prop_val>.*)\s*$/)
property_value = md['prop_val']
logger.debug "Using extra properties from command line '#{md['prop_name']}' = '#{property_value}'"
if pmd = property_value.match(/^\s*!entity\s+(?<entity_type>[^\/]+)\/(?<entity_name>.*)\s*$/)
type = pmd['entity_type'].to_sym
name = pmd['entity_name']
referenced_entity = project.engine.entity(type, name)
property_value = referenced_entity.to_reference unless referenced_entity.nil?
puts_and_logs "Could not find entity '#{type.to_s}/#{name}' !", logs_as: :error, check_verbose: false if referenced_entity.nil?
if pd = property_value.match(/^\s*!entity\s+(?<entity_id>.+)\s*$/)
property_value = pd['entity_id']
esr = PowerStencil::Utils::EntityHelper::EntitySearchReference.from_string property_value
if esr
type, name = esr.to_a
referenced_entity = project.engine.entity(type, name)
property_value = referenced_entity.to_reference unless referenced_entity.nil?
puts_and_logs "Could not find entity '#{type.to_s}/#{name}' !", logs_as: :error, check_verbose: false if referenced_entity.nil?
end
end
entity_as_hash[md['prop_name'].to_sym] = property_value
else
raise PowerStencil::Error, "Invalid command line property definition: '#{property_def}'"
end
......
......@@ -3,11 +3,7 @@ module PowerStencil
module EntityHelper
EntitySearchReference = Struct.new(:type, :name) do
def as_path
[type, name].map(&:to_s).join '/'
end
end
include PowerStencil::Utils::EntityHelper
def describe_entity_types(entity_types)
report = {}
......@@ -132,9 +128,9 @@ module PowerStencil
criteria = stack
else
stack.each do |param|
if md = param.match(/^\s*(?<type>[^\/]+)\/(?<name>.+)\s*$/)
next_entity_reference.type = md[:type].to_sym
next_entity_reference.name = md[:name]
esr = EntitySearchReference.from_string param
if esr
esr.fill next_entity_reference
else
if next_entity_reference.type.nil? or next_entity_reference.type.empty?
next_entity_reference.type = param.to_sym
......
......@@ -19,9 +19,9 @@ module PowerStencil
def entity(type_or_path, name = nil)
type, name = if name.nil?
md = type_or_path.match /^(?<type>[^\/]+)\/(?<name>.*)$/
if md
[md['type'].to_sym, md['name']]
esr = PowerStencil::Utils::EntityHelper::EntitySearchReference.from_string type_or_path
if esr
esr.to_a
else
raise PowerStencil::Error, "Invalid entity id: '#{type_or_path}'"
end
......
......@@ -56,7 +56,7 @@ module PowerStencil
end
def apply_plugins_dsl_definition(context)
project.plugins.each do |_, plugin|
project.plugins_sorted_by_dependency.each do |plugin|
plugin.apply_extra_dsl context
end
end
......
......@@ -17,12 +17,12 @@ module PowerStencil
logger.debug 'Starting PowerStencil initialization...'
setup_system_processors
setup_universe_compiler_logger
try_to_load_project fail_on_error: false
project fail_on_error: false
logger.debug 'PowerStencil initialization complete'
end
def project
@project ||= try_to_load_project
def project(fail_on_error: true)
@project ||= try_to_load_project fail_on_error: fail_on_error
end
private
......
......@@ -67,7 +67,7 @@ module PowerStencil
attr_reader :project
def setup_plugin
load_capabilities
determine_capabilities
load_plugin_specific_config
load_yaml_command_definition
end
......
......@@ -19,7 +19,7 @@ module PowerStencil
private
def load_capabilities
def determine_capabilities
yaml_file = plugin_capabilities_definition_file
unless File.exists? yaml_file and File.file? yaml_file and File.readable? yaml_file
raise PowerStencil::Error, "Plugin '#{self.name}' has no definition file !"
......
module PowerStencil
module Utils
module EntityHelper
EntitySearchReference = Struct.new(:type, :name) do
def self.from_string(string)
if md = string.match(/^\s*(?<type>[^\/]+)\/\s*(?<name>.+)\s*$/)
return new md[:type].to_sym, md[:name]
end
false
end
def as_path
to_a.map(&:to_s).join '/'
end
def to_a
[type, name]
end
def fill(something)
something.type = type
something.name = name
end
end
end
end
end
\ No newline at end of file
module PowerStencil
VERSION = '0.9.6'.freeze
VERSION = '0.9.7'.freeze
end
......@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'climatic', '~> 0.2.35'
spec.add_dependency 'dir_glob_ignore', '~> 0.3'
spec.add_dependency 'universe_compiler', '~> 0.5.5'
spec.add_dependency 'universe_compiler', '~> 0.5.6'
spec.add_dependency 'pry'
spec.add_dependency 'git' , '~> 1.5.0'
spec.add_dependency 'haml', '~> 5.1.2'
......