tla-sbuilder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +328 -0
- data/VERSION +1 -0
- data/bin/sbuilder.rb +5 -0
- data/lib/cli/cli-customer.rb +420 -0
- data/lib/cli/cli-example.rb +92 -0
- data/lib/cli/cli-pet.rb +767 -0
- data/lib/cli/cli-text.rb +226 -0
- data/lib/cli/cli.rb +298 -0
- data/lib/sbuilder.rb +52 -0
- data/lib/sbuilder/constants.rb +72 -0
- data/lib/sbuilder/controller.rb +798 -0
- data/lib/sbuilder/default-sbuilder.yaml +372 -0
- data/lib/sbuilder/domain.rb +124 -0
- data/lib/sbuilder/domain_cardinality.rb +37 -0
- data/lib/sbuilder/domain_value.rb +81 -0
- data/lib/sbuilder/exception.rb +27 -0
- data/lib/sbuilder/extension_loader.rb +721 -0
- data/lib/sbuilder/factory.rb +234 -0
- data/lib/sbuilder/model.rb +356 -0
- data/lib/sbuilder/mustache/template.rb +125 -0
- data/lib/sbuilder/mustache/template_reader.rb +206 -0
- data/lib/sbuilder/mustache/template_reader_context.rb +371 -0
- data/lib/sbuilder/param_set.rb +132 -0
- data/lib/sbuilder/param_set_db.rb +20 -0
- data/lib/sbuilder/param_set_def.rb +57 -0
- data/lib/sbuilder/param_set_if.rb +68 -0
- data/lib/sbuilder/param_set_loader.rb +77 -0
- data/lib/sbuilder/param_set_loader_swagger.rb +424 -0
- data/lib/sbuilder/param_set_step.rb +62 -0
- data/lib/sbuilder/param_sets.rb +54 -0
- data/lib/sbuilder/parameter.rb +97 -0
- data/lib/sbuilder/parameter_container.rb +72 -0
- data/lib/sbuilder/parameter_dom.rb +70 -0
- data/lib/sbuilder/parameter_ref.rb +71 -0
- data/lib/sbuilder/resolver.rb +78 -0
- data/lib/sbuilder/resolver_loader.rb +79 -0
- data/lib/sbuilder/resolver_loader_yaml.rb +103 -0
- data/lib/sbuilder/resolver_rule.rb +36 -0
- data/lib/sbuilder/resolver_rule_match.rb +55 -0
- data/lib/sbuilder/resolver_rule_ref.rb +37 -0
- data/lib/utils/hash_inject.rb +12 -0
- data/lib/utils/logger.rb +80 -0
- data/lib/utils/netio.rb +58 -0
- data/lib/utils/string_inject.rb +10 -0
- data/lib/utils/version.rb +13 -0
- data/mustache/cfg/const_def.mustache +8 -0
- data/mustache/cfg/const_run.mustache +3 -0
- data/mustache/cfg/invariant-infrastructure-service.mustache +4 -0
- data/mustache/cfg/macro_run.mustache +6 -0
- data/mustache/cfg/module_footer.mustache +0 -0
- data/mustache/cfg/module_header.mustache +7 -0
- data/mustache/data-model-dump.mustache +19 -0
- data/mustache/data-model-footer.mustache +5 -0
- data/mustache/data-model-header.mustache +16 -0
- data/mustache/definition_types.mustache +40 -0
- data/mustache/domains.mustache +20 -0
- data/mustache/domains_assign.mustache +22 -0
- data/mustache/domains_run.mustache +21 -0
- data/mustache/extend/extend_assumptions.mustache +7 -0
- data/mustache/extend/extend_const.mustache +5 -0
- data/mustache/extend/extend_implementation.mustache +9 -0
- data/mustache/extend/extend_invariant.mustache +7 -0
- data/mustache/extend/extend_invariant_cfg.mustache +7 -0
- data/mustache/extend/extend_macros.mustache +19 -0
- data/mustache/extend/extend_operations.mustache +9 -0
- data/mustache/extend/extend_state.mustache +9 -0
- data/mustache/infrastructure-service-init.mustache +36 -0
- data/mustache/infrastructure-service-variables.mustache +10 -0
- data/mustache/interface_processes.mustache +38 -0
- data/mustache/interface_stubs_dummy.mustache +13 -0
- data/mustache/interface_types.mustache +52 -0
- data/mustache/markdown-header.mustache +24 -0
- data/mustache/markdown-toc.mustache +13 -0
- data/mustache/name_definition_type.mustache +5 -0
- data/mustache/name_domain.mustache +5 -0
- data/mustache/name_domain_value.mustache +5 -0
- data/mustache/name_domain_value_prefix.mustache +5 -0
- data/mustache/name_interface_response_type.mustache +6 -0
- data/mustache/name_interface_type.mustache +6 -0
- data/mustache/name_parameter_definition.mustache +5 -0
- data/mustache/name_parameter_type.mustache +6 -0
- data/mustache/name_process.mustache +6 -0
- data/mustache/name_type_invariant.mustache +5 -0
- data/mustache/name_variable.mustache +6 -0
- data/mustache/operator-infrastructure-service.mustache +13 -0
- data/mustache/possibility/module_extends.mustache +1 -0
- data/mustache/possibility/module_footer.mustache +1 -0
- data/mustache/possibility/module_header.mustache +8 -0
- data/mustache/possibility/possibility_definition.mustache +12 -0
- data/mustache/possibility/possibility_directive.mustache +1 -0
- data/mustache/possibility/possility_setup.mustache +28 -0
- data/mustache/setup/module_footer.mustache +1 -0
- data/mustache/setup/module_header.mustache +9 -0
- data/mustache/setup/operator_run.mustache +7 -0
- data/mustache/setup/operator_tick.mustache +2 -0
- data/mustache/setup/steps_run.mustache +22 -0
- data/mustache/setup/steps_run_bind_rule.mustache +51 -0
- data/mustache/setup/steps_run_bind_set.mustache +37 -0
- data/mustache/setup/steps_run_parameterBind.mustache +80 -0
- data/mustache/setup/steps_run_parameterExact.mustache +79 -0
- data/mustache/state_type_invariant-infrastructure-service.mustache +49 -0
- data/mustache/state_type_invariant.mustache +17 -0
- data/mustache/state_type_invariant_cfg.mustache +18 -0
- data/mustache/state_variables.mustache +20 -0
- data/mustache/tla/const_def.mustache +5 -0
- data/mustache/tla/const_run.mustache +3 -0
- data/mustache/tla/macro-infrastructure-service.mustache +14 -0
- data/mustache/tla/macro_run.mustache +40 -0
- data/mustache/tla/module_footer.mustache +2 -0
- data/mustache/tla/module_header.mustache +9 -0
- data/mustache/tla/operator_run.mustache +8 -0
- data/mustache/tla/operators-infrastructure-service.mustache +12 -0
- data/mustache/tla/plc_define_footer.mustache +1 -0
- data/mustache/tla/plc_define_header.mustache +1 -0
- data/mustache/tla/plc_define_run.mustache +59 -0
- data/mustache/tla/plc_footer.mustache +2 -0
- data/mustache/tla/plc_header.mustache +2 -0
- data/mustache/tla/plc_run_state.mustache +12 -0
- data/mustache/tla/plc_tail.mustache +8 -0
- data/mustache/tla/plc_translation.mustache +2 -0
- data/resources/schema/json_schema/draft-04.json +150 -0
- data/resources/schema/swagger/2.0/schema.json +1591 -0
- data/src-extend/README +2 -0
- data/src-extend/extend/extend_assumptions.mustache +7 -0
- data/src-extend/extend/extend_const.mustache +5 -0
- data/src-extend/extend/extend_implementation.mustache +9 -0
- data/src-extend/extend/extend_invariant.mustache +11 -0
- data/src-extend/extend/extend_invariant_cfg.mustache +7 -0
- data/src-extend/extend/extend_macros.mustache +19 -0
- data/src-extend/extend/extend_operations.mustache +9 -0
- data/src-extend/extend/extend_state.mustache +9 -0
- data/src-extend/extend_app/assumption +20 -0
- data/src-extend/extend_app/correctness +19 -0
- data/src-extend/extend_app/correctness.cfg +9 -0
- data/src-extend/extend_app/infrastructure +25 -0
- data/src-extend/extend_app/interface +11 -0
- data/src-extend/extend_app/operator +18 -0
- data/src-extend/extend_app/possibility +16 -0
- data/src-extend/extend_app/service +33 -0
- data/src-extend/extend_app/state +16 -0
- data/src-extend/extend_app/transaction +22 -0
- data/src/pet/assumption +29 -0
- data/src/pet/assumption_address_domains.tla +12 -0
- data/src/pet/assumption_domains.tla +16 -0
- data/src/pet/assumption_generic.tla +8 -0
- data/src/pet/assumption_id_domains.tla +2 -0
- data/src/pet/assumption_owner_domains.tla +14 -0
- data/src/pet/assumption_pet_domains.tla +16 -0
- data/src/pet/assumption_tag_domains.tla +13 -0
- data/src/pet/correctness +24 -0
- data/src/pet/correctness.cfg +9 -0
- data/src/pet/correctness_coherent_owner_address.tla +6 -0
- data/src/pet/correctness_pet_name.tla +4 -0
- data/src/pet/correctness_ref_tag.tla +13 -0
- data/src/pet/correctness_type_invariants.tla +12 -0
- data/src/pet/correctness_unique_pet.tla +3 -0
- data/src/pet/correctness_unique_tag.tla +3 -0
- data/src/pet/docs/Petstore.md +117 -0
- data/src/pet/extend/extend_assumptions.mustache +7 -0
- data/src/pet/extend/extend_implementation.mustache +9 -0
- data/src/pet/extend/extend_invariant.mustache +11 -0
- data/src/pet/extend/extend_invariant_cfg.mustache +7 -0
- data/src/pet/extend/extend_macros.mustache +19 -0
- data/src/pet/extend/extend_operations.mustache +9 -0
- data/src/pet/extend/extend_state.mustache +9 -0
- data/src/pet/infrastructure +25 -0
- data/src/pet/infrastructure_id_get.tla +24 -0
- data/src/pet/interface +12 -0
- data/src/pet/interface_delete_pet.tla +5 -0
- data/src/pet/interface_get_pet.tla +4 -0
- data/src/pet/interface_post_pet.tla +5 -0
- data/src/pet/interface_post_tag.tla +5 -0
- data/src/pet/interface_put_tag.tla +3 -0
- data/src/pet/operator +30 -0
- data/src/pet/operator_find_tag_by_owner_name.tla +1 -0
- data/src/pet/operator_get_pet.tla +4 -0
- data/src/pet/operator_get_pet_by_tag.tla +4 -0
- data/src/pet/operator_get_tag.tla +10 -0
- data/src/pet/operator_new_owner.tla +3 -0
- data/src/pet/operator_new_pet.tla +13 -0
- data/src/pet/operator_new_tag.tla +3 -0
- data/src/pet/operator_next_pet_id.tla +3 -0
- data/src/pet/operator_responses.tla +8 -0
- data/src/pet/operator_tag_exists.tla +2 -0
- data/src/pet/operator_tag_owner_validated.tla +2 -0
- data/src/pet/operator_tag_referenced.tla +4 -0
- data/src/pet/operator_valid_owner.tla +17 -0
- data/src/pet/operator_valid_pet.tla +6 -0
- data/src/pet/operator_valid_tag.tla +5 -0
- data/src/pet/possibility +18 -0
- data/src/pet/possibility_at_least_two_tags.tla +12 -0
- data/src/pet/possibility_invalid_tag_address.tla +8 -0
- data/src/pet/service +35 -0
- data/src/pet/service_pet_delete.tla +11 -0
- data/src/pet/service_pet_get.tla +27 -0
- data/src/pet/service_pet_post.tla +78 -0
- data/src/pet/service_tag_post.tla +53 -0
- data/src/pet/service_tag_put.tla +82 -0
- data/src/pet/state +16 -0
- data/src/pet/state_infra.tla +6 -0
- data/src/pet/state_pet.tla +5 -0
- data/src/pet/state_tag_id.tla +2 -0
- data/src/pet/transaction +23 -0
- data/src/pet/transaction_delete_pet.tla +13 -0
- data/src/pet/transaction_enter_pet.tla +13 -0
- data/src/pet/transaction_enter_tag.tla +56 -0
- data/src/pet/transaction_error.tla +23 -0
- data/tla-sbuilder.gemspec +43 -0
- metadata +353 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
|
2
|
+
module Sbuilder
|
3
|
+
|
4
|
+
class ResolverLoader
|
5
|
+
|
6
|
+
attr_reader :factory # to create stuff
|
7
|
+
attr_accessor :controller # get sets when load starts
|
8
|
+
|
9
|
+
# ------------------------------------------------------------------
|
10
|
+
# mixer
|
11
|
+
PROGNAME = "ResolverLoader" # progname for logger
|
12
|
+
include Sbuilder::Utils::MyLogger # mix logger
|
13
|
+
|
14
|
+
|
15
|
+
# ------------------------------------------------------------------
|
16
|
+
# constructore
|
17
|
+
|
18
|
+
def initialize( factory, options = {} )
|
19
|
+
@logger = getLogger( PROGNAME, options )
|
20
|
+
@logger.info( "#{__method__} initialized" )
|
21
|
+
@factory = factory
|
22
|
+
end
|
23
|
+
|
24
|
+
# ------------------------------------------------------------------
|
25
|
+
# load mapper from 'filePath'
|
26
|
+
def load( filePath, controller )
|
27
|
+
@controller = controller
|
28
|
+
begin
|
29
|
+
mappers = doLoad( filePath )
|
30
|
+
rescue Exception => ee
|
31
|
+
msg = "Error #{ee} when loading '#{filePath}', caused by #{ee.backtrace.join("\n")} \n\n"
|
32
|
+
@logger.error( "#{__method__} #{msg}" )
|
33
|
+
raise LoaderException.new( msg )
|
34
|
+
end
|
35
|
+
return mappers
|
36
|
+
end
|
37
|
+
|
38
|
+
# create new mapper object
|
39
|
+
def createResolver
|
40
|
+
factory.createResolver
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# create new rule object
|
45
|
+
def createResolverRule
|
46
|
+
factory.createResolverRule
|
47
|
+
end
|
48
|
+
|
49
|
+
# domain encountered during load phase
|
50
|
+
def domainEncountered( domain )
|
51
|
+
controller.domainEncountered( domain )
|
52
|
+
end
|
53
|
+
|
54
|
+
# doLoad infoms super class for a new mapper, delegate to controller
|
55
|
+
def mapperCreated( mapper )
|
56
|
+
controller.mapperCreated( mapper )
|
57
|
+
end
|
58
|
+
|
59
|
+
# return mapper with name in controller - error if not found
|
60
|
+
def findResolver( name )
|
61
|
+
mapper = @controller.findResolver( name )
|
62
|
+
raise "Resolver #{name} not found" if mapper.nil?
|
63
|
+
return mapper
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# ------------------------------------------------------------------
|
68
|
+
# sub-class should implement the doload method
|
69
|
+
def doLoad( filePath )
|
70
|
+
msg = "Sub class should implement doLoad -method"
|
71
|
+
@logger.error( "#{__method__} #{msg}" )
|
72
|
+
raise NoMethodError.new( msg )
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end # class ResolverLoader
|
77
|
+
|
78
|
+
|
79
|
+
end # module
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Sbuilder
|
2
|
+
|
3
|
+
class ResolverLoader_YAML < ResolverLoader
|
4
|
+
|
5
|
+
# ------------------------------------------------------------------
|
6
|
+
# mixer
|
7
|
+
PROGNAME = "ResolverLoaderYAML" # progname for logger
|
8
|
+
include Sbuilder::Utils::MyLogger # mix logger
|
9
|
+
|
10
|
+
# ------------------------------------------------------------------
|
11
|
+
# constructore
|
12
|
+
|
13
|
+
def initialize( factory, options = {} )
|
14
|
+
super( factory, options )
|
15
|
+
@logger = getLogger( PROGNAME, options )
|
16
|
+
@logger.info( "#{__method__} initialized" )
|
17
|
+
end
|
18
|
+
|
19
|
+
# ------------------------------------------------------------------
|
20
|
+
# build phase
|
21
|
+
|
22
|
+
def doLoad( yamlPath )
|
23
|
+
@logger.info( "#{__method__} yamlPath=#{yamlPath}" )
|
24
|
+
if !yamlPath then
|
25
|
+
msg = "yamlPath empty"
|
26
|
+
@logger.info( "#{__method__} #{msg}" )
|
27
|
+
raise msg
|
28
|
+
end
|
29
|
+
# get lines from net or from a file
|
30
|
+
yaml_lines = Sbuilder::Utils::NetIo.read_lines( yamlPath )
|
31
|
+
yaml = YAML.load( yaml_lines )
|
32
|
+
mappers = yaml2mapper( yaml )
|
33
|
+
@logger.info( "#{__method__} loaded =#{mappers.length} mappers" )
|
34
|
+
return mappers
|
35
|
+
end
|
36
|
+
|
37
|
+
# iterate yaml && create mapper && config
|
38
|
+
private def yaml2mapper( yamlArray )
|
39
|
+
mappers = []
|
40
|
+
yamlArray && yamlArray.each do |mapperDef|
|
41
|
+
|
42
|
+
# create mapper & configure it
|
43
|
+
mapper = factory.createResolver( Sbuilder::Constants::MAPPER_YAML )
|
44
|
+
matcher = mapperDef['Matcher']
|
45
|
+
mapper.setMatch( matcher )
|
46
|
+
mapper.setName( mapperDef['Name'] )
|
47
|
+
|
48
|
+
# inform paraent class that created
|
49
|
+
mapperCreated( mapper )
|
50
|
+
@logger.info( "#{__method__} matcher #{matcher} for #{mapperDef['Name']}" )
|
51
|
+
mappers << mapper
|
52
|
+
|
53
|
+
# validate mapperDef
|
54
|
+
# raise "mapper definition #{mapperDef} should define property 'Rules'" unless mapperDef['Rules']
|
55
|
+
|
56
|
+
mapperDef['Rules'] && mapperDef['Rules'].each do |ruleDef|
|
57
|
+
|
58
|
+
if ruleDef['Matcher'] then
|
59
|
+
|
60
|
+
# rule implementation
|
61
|
+
yaml2mapperMatchRule( mapper, ruleDef )
|
62
|
+
elsif ruleDef['Ref'] then
|
63
|
+
|
64
|
+
# include existing rules
|
65
|
+
yaml2mapperRefRule( mapper, ruleDef )
|
66
|
+
else
|
67
|
+
raise "Unknown mapper rule #{ruleDef} in #{mapperDef['Name']} - should define 'Matcher' or 'Ref' properties"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
mappers
|
72
|
+
end
|
73
|
+
|
74
|
+
# create match mapper rule && config && add to mapprt
|
75
|
+
private def yaml2mapperMatchRule( mapper, ruleDef )
|
76
|
+
rule = factory.createResolverRule( Sbuilder::Constants::MAPPER_RULE_MATCH )
|
77
|
+
domainName = ruleDef['Domain']
|
78
|
+
domainEncountered( domainName )
|
79
|
+
rule.config( ruleDef['Matcher'], domainName )
|
80
|
+
mapper.add_rule( rule )
|
81
|
+
end
|
82
|
+
|
83
|
+
# create reference mapper rule && config && add to mapprt
|
84
|
+
private def yaml2mapperRefRule( mapper, ruleDef )
|
85
|
+
# Create rule
|
86
|
+
rule = factory.createResolverRule( Sbuilder::Constants::MAPPER_RULE_REF )
|
87
|
+
|
88
|
+
# Validate context
|
89
|
+
raise "Expect ruleDef #{ruleDef} to define 'Ref' in mapper #{mapper.name}" unless ruleDef['Ref']
|
90
|
+
name = ruleDef['Ref']
|
91
|
+
referencedResolver = findResolver( name = ruleDef['Ref'] )
|
92
|
+
|
93
|
+
# configure
|
94
|
+
rule.setRef( referencedResolver );
|
95
|
+
|
96
|
+
# Finally add to list
|
97
|
+
mapper.add_rule( rule )
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
end
|
103
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
module Sbuilder
|
3
|
+
|
4
|
+
class ResolverRule
|
5
|
+
|
6
|
+
|
7
|
+
# ------------------------------------------------------------------
|
8
|
+
# mixer
|
9
|
+
PROGNAME = "ResolverRule" # progname for logger
|
10
|
+
include Sbuilder::Utils::MyLogger # mix logger
|
11
|
+
|
12
|
+
# ------------------------------------------------------------------
|
13
|
+
# constrcutore
|
14
|
+
def initialize( options = {} )
|
15
|
+
@logger = getLogger( PROGNAME, options )
|
16
|
+
@logger.info( "#{__method__} initialized" )
|
17
|
+
end
|
18
|
+
|
19
|
+
# ------------------------------------------------------------------
|
20
|
+
# resolve domain
|
21
|
+
|
22
|
+
# return true if domain resolved
|
23
|
+
def applyRule( parameter, model )
|
24
|
+
doApplyRule( parameter, model )
|
25
|
+
end
|
26
|
+
|
27
|
+
def doApplyRule( parameter, model )
|
28
|
+
msg = "Sub class should implement doApplyRule -method"
|
29
|
+
@logger.error( "#{__method__} #{msg}" )
|
30
|
+
raise NoMethodError.new( msg )
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Sbuilder
|
2
|
+
|
3
|
+
class ResolverRuleMatch < ResolverRule
|
4
|
+
|
5
|
+
attr_reader :matchRule # string or regexp
|
6
|
+
attr_reader :domain
|
7
|
+
|
8
|
+
# ------------------------------------------------------------------
|
9
|
+
# mixer
|
10
|
+
PROGNAME = "ResolverRuleMatch" # progname for logger
|
11
|
+
include Sbuilder::Utils::MyLogger # mix logger
|
12
|
+
|
13
|
+
# ------------------------------------------------------------------
|
14
|
+
# constrcutore
|
15
|
+
def initialize( options = {} )
|
16
|
+
@logger = getLogger( PROGNAME, options )
|
17
|
+
@logger.info( "#{__method__} initialized" )
|
18
|
+
super( options )
|
19
|
+
end
|
20
|
+
|
21
|
+
# set properties when loading
|
22
|
+
def config( matchRule, domain )
|
23
|
+
@matchRule = matchRule
|
24
|
+
@domain = domain
|
25
|
+
end
|
26
|
+
|
27
|
+
# ------------------------------------------------------------------
|
28
|
+
# resolve domain
|
29
|
+
def match( parameter )
|
30
|
+
matchRule.is_a?( String ) ? parameter.name == matchRule : (parameter.name =~ matchRule) != nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# return true if domain resolved
|
34
|
+
def doApplyRule( parameter, model )
|
35
|
+
@logger.debug( "#{__method__} matchRule=#{matchRule}, matchRule.class=#{matchRule.class} on parameter.getName=#{parameter.getName}" )
|
36
|
+
|
37
|
+
# no need to resolve domain - Paramter_Ref?
|
38
|
+
return true unless parameter.respond_to?( :domain )
|
39
|
+
|
40
|
+
# its already read
|
41
|
+
return true if parameter.domain
|
42
|
+
if match( parameter ) then
|
43
|
+
@logger.info( "#{__method__} setDomain '#{domain}' on parameter '#{parameter.getName}' based on rule '#{matchRule}'" )
|
44
|
+
#
|
45
|
+
parameter.setDomain( domain )
|
46
|
+
parameter.resolveDomain( model )
|
47
|
+
return true
|
48
|
+
end
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Sbuilder
|
2
|
+
|
3
|
+
class ResolverRuleRef < ResolverRule
|
4
|
+
|
5
|
+
|
6
|
+
attr_reader :ref # reference to mapper
|
7
|
+
# ------------------------------------------------------------------
|
8
|
+
# mixer
|
9
|
+
PROGNAME = "ResolverRuleRef" # progname for logger
|
10
|
+
include Sbuilder::Utils::MyLogger # mix logger
|
11
|
+
|
12
|
+
# ------------------------------------------------------------------
|
13
|
+
# constrcutore
|
14
|
+
def initialize( options = {} )
|
15
|
+
@logger = getLogger( PROGNAME, options )
|
16
|
+
@logger.info( "#{__method__} initialized" )
|
17
|
+
super( options )
|
18
|
+
end
|
19
|
+
|
20
|
+
# ------------------------------------------------------------------
|
21
|
+
# config
|
22
|
+
def setRef( mapperRef )
|
23
|
+
@ref = mapperRef
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
# ------------------------------------------------------------------
|
28
|
+
# resovele phase
|
29
|
+
|
30
|
+
def doApplyRule( parameter, model )
|
31
|
+
# delegate to mapper being refencence
|
32
|
+
ref.applyRule( parameter, model )
|
33
|
+
end
|
34
|
+
|
35
|
+
end # class
|
36
|
+
end # module
|
37
|
+
|
data/lib/utils/logger.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
# see http://hawkins.io/2013/08/using-the-ruby-logger/
|
4
|
+
|
5
|
+
module Sbuilder
|
6
|
+
|
7
|
+
module Utils
|
8
|
+
|
9
|
+
module MyLogger
|
10
|
+
|
11
|
+
# no logging done
|
12
|
+
|
13
|
+
class NullLoger < Logger
|
14
|
+
def initialize(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def add(*args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def debug?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
@@logfile = nil # absolute path to log file
|
26
|
+
LOGFILE="sbuilder.log"
|
27
|
+
|
28
|
+
def logfile( options )
|
29
|
+
return @@logfile if @@logfile
|
30
|
+
@@logfile = options[:logfile] || File.join( Dir.getwd, LOGFILE )
|
31
|
+
end
|
32
|
+
|
33
|
+
def getLogger( progname, options={} )
|
34
|
+
|
35
|
+
level = get_level( options )
|
36
|
+
|
37
|
+
if level.nil?
|
38
|
+
|
39
|
+
return NullLoger.new
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
logger = Logger.new( logfile(options) )
|
44
|
+
logger.level=level
|
45
|
+
logger.progname = progname
|
46
|
+
return logger
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end # getLogger
|
51
|
+
|
52
|
+
# ------------------------------------------------------------------
|
53
|
+
private
|
54
|
+
|
55
|
+
def get_level( options )
|
56
|
+
|
57
|
+
# puts "#{__method__}: options=#{options}"
|
58
|
+
|
59
|
+
level_name = options && options[:log] ? options[:log] : ENV['LOG_LEVEL']
|
60
|
+
|
61
|
+
level = case level_name
|
62
|
+
when 'warn', 'WARN'
|
63
|
+
Logger::WARN
|
64
|
+
when 'info', 'INFO'
|
65
|
+
Logger::INFO
|
66
|
+
when 'debug', 'DEBUG'
|
67
|
+
Logger::DEBUG
|
68
|
+
when 'error', 'ERROR'
|
69
|
+
Logger::ERROR
|
70
|
+
else
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
return level
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/utils/netio.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module Sbuilder
|
6
|
+
|
7
|
+
module Utils
|
8
|
+
|
9
|
+
class NetIo
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def uri_exist?( uri )
|
14
|
+
if uri =~ URI::regexp
|
15
|
+
url = URI.parse( uri )
|
16
|
+
Net::HTTP.start(url.host, url.port) { |http|
|
17
|
+
return http.head(url.request_uri).code == "200"
|
18
|
+
}
|
19
|
+
else
|
20
|
+
return File.exist?( uri )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# if 'cacheFile' return line in 'cacheFile else read from 'uri' && write to 'cacheFile'
|
25
|
+
def read_lines_cached( uri, cacheFile = nil )
|
26
|
+
|
27
|
+
# cached
|
28
|
+
return File.read( cacheFile ) if !cacheFile.nil? && File.exist?( cacheFile )
|
29
|
+
|
30
|
+
# network access && create cache
|
31
|
+
lines = read_lines( uri )
|
32
|
+
cache_lines( cacheFile, lines ) unless cacheFile.nil?
|
33
|
+
|
34
|
+
#
|
35
|
+
return lines
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def read_lines( uri )
|
40
|
+
begin
|
41
|
+
open( uri ).read
|
42
|
+
rescue => e
|
43
|
+
msg = "Error #{e}, when reading from uri '#{uri}'"
|
44
|
+
raise msg
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# write lines in cache file
|
49
|
+
def cache_lines( cacheFile, lines )
|
50
|
+
File.open( cacheFile, "w" ) { |f| f.write( lines ) }
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|