Class: Sbuilder::SnippetLoaderSimple
- Inherits:
-
SnippetLoaderPlugin
- Object
- LoaderPluginRoot
- SnippetLoaderPlugin
- Sbuilder::SnippetLoaderSimple
- Extended by:
- Forwardable, SingleForwardable
- Defined in:
- lib/sbuilder/snippet_loader_simple.rb
Constant Summary collapse
- @@src_dir =
default directory where files are read
"./src"
Constants inherited from LoaderPluginRoot
Constants included from Utils::MyLogger
Constructor and configuration collapse
-
.configure(configuration) ⇒ Object
Class method to configure class ‘SnippetLoaderPlugin’.
-
#doConfigure(configuration) ⇒ Object
base class should implement ‘doConfigure’.
-
#initialize(options = {}) ⇒ SnippetLoaderSimple
constructor
——————————————————————.
Register snippets to sbuilder collapse
-
#doRegisterSnippets(snippetDefitions) ⇒ Object
Override abstract method in parent class for the implementation.
Simple plugin implementation collapse
-
#readFile(location) ⇒ String
Read file pointed by ‘location’.
-
#src_dir ⇒ String
Path to directory, where src files are.
-
#src_path(snippetDefition) ⇒ String
Path to file to read ‘url’ or
src_dir+file.
Methods included from SnippetLoaderPluginMixer
#registerMetatype, #registerSnippets, #setSnippetFacade, #snippetFacade, validateProperties
Methods inherited from LoaderPluginRoot
baseMetatypes, #configure, #logger, #oneOf, validateProperties, #validateProperties
Methods included from Utils::MyLogger
Constructor Details
#initialize(options = {}) ⇒ SnippetLoaderSimple
22 23 24 |
# File 'lib/sbuilder/snippet_loader_simple.rb', line 22 def initialize( = {} ) super( ) end |
Class Method Details
.configure(configuration) ⇒ Object
Class method to configure class ‘SnippetLoaderPlugin’
30 31 32 33 34 35 36 37 |
# File 'lib/sbuilder/snippet_loader_simple.rb', line 30 def self.configure( configuration ) return if configuration.nil? Sbuilder::Utils::Validate.validateProperties( configuration, Constants::VALIDATION[:snippet_loader_plugin][:class_config_required], Constants::VALIDATION[:snippet_loader_plugin][:class_config_allowed] ) @@src_dir = configuration['src_dir'] end |
Instance Method Details
#doConfigure(configuration) ⇒ Object
base class should implement ‘doConfigure’
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sbuilder/snippet_loader_simple.rb', line 41 def doConfigure( configuration ) if configuration.nil? logger.warn "#{__method__}: no cofiguration for #{self.class}" return end Sbuilder::Utils::Validate.validateProperties( configuration, Constants::VALIDATION[:snippet_loader_plugin][:object_config_required], Constants::VALIDATION[:snippet_loader_plugin][:object_config_allowed] ) # hash with metatypes as keys configuration['metatypes'] && configuration['metatypes'].each do |,desc| registerMetatype( , desc ) end end |
#doRegisterSnippets(snippetDefitions) ⇒ Object
Override abstract method in parent class for the implementation.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sbuilder/snippet_loader_simple.rb', line 69 def doRegisterSnippets( snippetDefitions ) logger.info "#{__method__}, loading snippetDefitions=#{snippetDefitions}" snippetDefitions && snippetDefitions.each do |snippetDefition| # gets actually delegated # Sbuilder::Utils::Validate.validateProperties( snippetDefition, PROPS_REQUIRED, PROPS_ALLOWED ) Utils::Validate.validateProperties( snippetDefition, Constants::VALIDATION[:snippet_loader_plugin][:required], Constants::VALIDATION[:snippet_loader_plugin][:allowed] ) # 0 allowed, max one allowed from url/file Utils::Validate.oneOf( snippetDefition, Constants::VALIDATION[:snippet_loader_plugin][:one_of_file_or_url], 0, 1 ) # read content of snippetDefition['file'] into a [String} snippetBody = readFile( src_path( snippetDefition ) ) if snippetDefition['file'] || snippetDefition['url'] # pass 'snippetBody' together with metatypes to facade snippetFacade.handOver( snippetDefition['metatype'], snippetDefition['appName'], snippetBody, snippetDefition['name'], ) end end |
#readFile(location) ⇒ String
Read file pointed by ‘location’
99 100 101 102 |
# File 'lib/sbuilder/snippet_loader_simple.rb', line 99 def readFile( location ) @logger.info "#{__method__}: location=#{location}" line = Sbuilder::Utils::NetIo.read_lines( location ) end |
#src_dir ⇒ String
Returns path to directory, where src files are.
115 116 117 |
# File 'lib/sbuilder/snippet_loader_simple.rb', line 115 def src_dir @@src_dir || "." end |
#src_path(snippetDefition) ⇒ String
Returns path to file to read ‘url’ or src_dir + file.
109 110 111 112 |
# File 'lib/sbuilder/snippet_loader_simple.rb', line 109 def src_path( snippetDefition ) return snippetDefition['url'] if snippetDefition['url'] return File.join( src_dir, snippetDefition['file']) end |