How to use inspect method of Plugins Package

Best Inspec_ruby code snippet using Plugins.inspect

test-database-inspector.rb

Source:test-database-inspector.rb Github

copy

Full Screen

...21 end22 private23 def report24 output = StringIO.new25 inspector = Groonga::DatabaseInspector.new(@database, @options)26 inspector.report(output)27 output.string28 end29 def create_reporter(output)30 Groonga::DatabaseInspector::Reporter.new(@database, @options, output)31 end32 def total_disk_usage33 @database.tables.inject(@database.disk_usage) do |previous, table|34 previous + total_table_disk_usage(table)35 end36 end37 def total_table_disk_usage(table)38 table.columns.inject(table.disk_usage) do |previous, column|39 previous + column.disk_usage40 end41 end42 def inspect_disk_usage(disk_usage)43 if disk_usage < (2 ** 20)44 "%.3fKiB" % (disk_usage / (2 ** 10).to_f)45 else46 "%.3fMiB" % (disk_usage / (2 ** 20).to_f)47 end48 end49 def inspect_sub_disk_usage(disk_usage)50 percent = disk_usage / total_disk_usage.to_f * 10051 "%s (%.3f%%)" % [inspect_disk_usage(disk_usage), percent]52 end53 def inspect_table(table)54 <<-INSPECTED55 #{table.name}:56 ID: #{table.id}57 Type: #{inspect_table_type(table)}58 Key type: #{inspect_key_type(table)}59 Tokenizer: #{inspect_tokenizer(table)}60 Normalizer: #{inspect_normalizer(table)}61 Path: <#{table.path}>62 Total disk usage: #{inspect_sub_disk_usage(total_table_disk_usage(table))}63 Disk usage: #{inspect_sub_disk_usage(table.disk_usage)}64 N records: #{table.size}65 N columns: #{table.columns.size}66#{inspect_columns(table.columns).chomp}67 INSPECTED68 end69 def inspect_table_type(table)70 case table71 when Groonga::Array72 "array"73 when Groonga::Hash74 "hash"75 when Groonga::PatriciaTrie76 "patricia trie"77 when Groonga::DoubleArrayTrie78 "double array trie"79 end80 end81 def inspect_key_type(table)82 if table.support_key?83 table.domain.name84 else85 "(no key)"86 end87 end88 def inspect_tokenizer(table)89 if table.support_key?90 tokenizer = table.default_tokenizer91 if tokenizer92 tokenizer.name93 else94 "(no tokenizer)"95 end96 else97 "(no key)"98 end99 end100 def inspect_normalizer(table)101 if table.support_key?102 normalizer = table.normalizer103 if normalizer104 normalizer.name105 else106 "(no normalizer)"107 end108 else109 "(no key)"110 end111 end112 def inspect_columns(columns)113 if columns.empty?114 <<-INSPECTED115 Columns:116 None117 INSPECTED118 else119 inspected = " Columns:\n"120 columns.each do |column|121 inspected << inspect_column(column)122 end123 inspected124 end125 end126 def inspect_column(column)127 <<-INSPECTED128 #{column.local_name}:129 ID: #{column.id}130 Type: #{inspect_column_type(column)}131 Value type: #{inspect_value_type(column.range)}132 Path: <#{column.path}>133 Disk usage: #{inspect_sub_disk_usage(column.disk_usage)}134 INSPECTED135 end136 def inspect_column_type(column)137 case column138 when Groonga::FixSizeColumn139 "scalar"140 when Groonga::VariableSizeColumn141 if column.vector?142 "vector"143 else144 "scalar"145 end146 else147 "index"148 end149 end150 def inspect_value_type(range)151 if range.nil?152 "(no value)"153 else154 range.name155 end156 end157 class DatabaseTest < self158 def test_empty159 assert_equal(<<-INSPECTED, report)160Database161 Path: <#{@database_path}>162 Total disk usage: #{inspect_disk_usage(total_disk_usage)}163 Disk usage: #{inspect_sub_disk_usage(@database.disk_usage)}164 N records: 0165 N tables: 0166 N columns: 0167 Plugins:168 None169 Tables:170 None171 INSPECTED172 end173 def test_no_show_tables174 @options.show_tables = false175 assert_equal(<<-INSPECTED, report)176Database177 Path: <#{@database_path}>178 Total disk usage: #{inspect_disk_usage(total_disk_usage)}179 Disk usage: #{inspect_sub_disk_usage(@database.disk_usage)}180 N records: 0181 N tables: 0182 N columns: 0183 Plugins:184 None185 INSPECTED186 end187 class NRecordsTest < self188 setup189 def setup_tables190 Groonga::Schema.define do |schema|191 schema.create_table("Users") do |table|192 end193 schema.create_table("Bookmarks") do |table|194 end195 end196 @users = context["Users"]197 @bookmarks = context["Bookmarks"]198 end199 def test_no_records200 assert_equal(inspected(0), report)201 end202 def test_has_records203 @users.add204 @users.add205 @bookmarks.add206 assert_equal(inspected(3), report)207 end208 private209 def inspected(n_records)210 <<-INSPECTED211Database212 Path: <#{@database_path}>213 Total disk usage: #{inspect_disk_usage(total_disk_usage)}214 Disk usage: #{inspect_sub_disk_usage(@database.disk_usage)}215 N records: #{n_records}216 N tables: 2217 N columns: 0218 Plugins:219 None220 Tables:221#{inspect_table(@bookmarks).chomp}222#{inspect_table(@users).chomp}223 INSPECTED224 end225 end226 class NTablesTest < self227 def test_no_tables228 assert_equal(inspected(0), report)229 end230 def test_has_tables231 Groonga::Schema.define do |schema|232 schema.create_table("Users") do |table|233 end234 schema.create_table("Bookmarks") do |table|235 end236 end237 assert_equal(inspected(2), report)238 end239 private240 def inspected(n_tables)241 inspected_tables = " Tables:\n"242 if @database.tables.empty?243 inspected_tables << " None\n"244 else245 @database.tables.each do |table|246 inspected_tables << inspect_table(table)247 end248 end249 <<-INSPECTED250Database251 Path: <#{@database_path}>252 Total disk usage: #{inspect_disk_usage(total_disk_usage)}253 Disk usage: #{inspect_sub_disk_usage(@database.disk_usage)}254 N records: 0255 N tables: #{n_tables}256 N columns: 0257 Plugins:258 None259#{inspected_tables.chomp}260 INSPECTED261 end262 end263 class NColumnsTest < self264 setup265 def setup_tables266 Groonga::Schema.define do |schema|267 schema.create_table("Users") do |table|268 end269 schema.create_table("Bookmarks") do |table|270 end271 end272 @users = context["Users"]273 @bookmarks = context["Bookmarks"]274 end275 def test_no_columns276 assert_equal(inspected(0), report)277 end278 def test_has_columns279 Groonga::Schema.define do |schema|280 schema.create_table("Users") do |table|281 table.short_text("name")282 table.int8("age")283 end284 schema.create_table("Bookmarks") do |table|285 table.text("description")286 end287 end288 assert_equal(inspected(3), report)289 end290 private291 def inspected(n_columns)292 <<-INSPECTED293Database294 Path: <#{@database_path}>295 Total disk usage: #{inspect_disk_usage(total_disk_usage)}296 Disk usage: #{inspect_sub_disk_usage(@database.disk_usage)}297 N records: 0298 N tables: 2299 N columns: #{n_columns}300 Plugins:301 None302 Tables:303#{inspect_table(@bookmarks).chomp}304#{inspect_table(@users).chomp}305 INSPECTED306 end307 end308 class PluginsTest < self309 def test_no_plugins310 assert_equal(inspected(<<-INSPECTED), report)311 Plugins:312 None313 INSPECTED314 end315 def test_has_plugin316 context.register_plugin("query_expanders/tsv")317 assert_equal(inspected(<<-INSPECTED), report)318 Plugins:319 * query_expanders/tsv#{Groonga::Plugin.suffix}320 INSPECTED321 end322 private323 def inspected(inspected_plugins)324 <<-INSPECTED325Database326 Path: <#{@database_path}>327 Total disk usage: #{inspect_disk_usage(total_disk_usage)}328 Disk usage: #{inspect_sub_disk_usage(@database.disk_usage)}329 N records: 0330 N tables: 0331 N columns: 0332#{inspected_plugins.chomp}333 Tables:334 None335 INSPECTED336 end337 end338 end339 class TableTest < self340 private341 def report342 output = StringIO.new343 reporter = create_reporter(output)344 reporter.send(:report_table, @table)345 output.string346 end347 def inspect_columns(table)348 super.gsub(/^ /, "")349 end350 class NRecordsTest < self351 setup352 def setup_tables353 Groonga::Schema.define do |schema|354 schema.create_table("Users") do |table|355 end356 end357 @table = context["Users"]358 end359 def test_no_record360 assert_equal(inspected(0), report)361 end362 def test_empty363 @table.add364 @table.add365 @table.add366 assert_equal(inspected(3), report)367 end368 private369 def inspected(n_records)370 <<-INSPECTED371#{@table.name}:372 ID: #{@table.id}373 Type: #{inspect_table_type(@table)}374 Key type: #{inspect_key_type(@table)}375 Tokenizer: #{inspect_tokenizer(@table)}376 Normalizer: #{inspect_normalizer(@table)}377 Path: <#{@table.path}>378 Total disk usage: #{inspect_sub_disk_usage(total_table_disk_usage(@table))}379 Disk usage: #{inspect_sub_disk_usage(@table.disk_usage)}380 N records: #{n_records}381 N columns: #{@table.columns.size}382#{inspect_columns(@table.columns).chomp}383 INSPECTED384 end385 end386 class TypeTest < self387 def test_array388 Groonga::Schema.create_table("Users")389 @table = Groonga["Users"]390 assert_equal(inspected("array"), report)391 end392 def test_hash393 Groonga::Schema.create_table("Users",394 :type => :hash,395 :key_type => :short_text)396 @table = Groonga["Users"]397 assert_equal(inspected("hash"), report)398 end399 def test_patricia_trie400 Groonga::Schema.create_table("Users",401 :type => :patricia_trie,402 :key_type => :short_text)403 @table = Groonga["Users"]404 assert_equal(inspected("patricia trie"), report)405 end406 def test_double_array_trie407 Groonga::Schema.create_table("Users",408 :type => :double_array_trie,409 :key_type => :short_text)410 @table = Groonga["Users"]411 assert_equal(inspected("double array trie"), report)412 end413 private414 def inspected(type)415 <<-INSPECTED416#{@table.name}:417 ID: #{@table.id}418 Type: #{type}419 Key type: #{inspect_key_type(@table)}420 Tokenizer: #{inspect_tokenizer(@table)}421 Normalizer: #{inspect_normalizer(@table)}422 Path: <#{@table.path}>423 Total disk usage: #{inspect_sub_disk_usage(total_table_disk_usage(@table))}424 Disk usage: #{inspect_sub_disk_usage(@table.disk_usage)}425 N records: #{@table.size}426 N columns: #{@table.columns.size}427#{inspect_columns(@table.columns).chomp}428 INSPECTED429 end430 end431 class KeyTypeTest < self432 def test_array433 Groonga::Schema.create_table("Users")434 @table = Groonga["Users"]435 assert_equal(inspected("(no key)"), report)436 end437 def test_key_support_table438 Groonga::Schema.create_table("Users",439 :type => :hash,440 :key_type => "Int32")441 @table = Groonga["Users"]442 assert_equal(inspected("Int32"), report)443 end444 private445 def inspected(key_type)446 <<-INSPECTED447#{@table.name}:448 ID: #{@table.id}449 Type: #{inspect_table_type(@table)}450 Key type: #{key_type}451 Tokenizer: #{inspect_tokenizer(@table)}452 Normalizer: #{inspect_normalizer(@table)}453 Path: <#{@table.path}>454 Total disk usage: #{inspect_sub_disk_usage(total_table_disk_usage(@table))}455 Disk usage: #{inspect_sub_disk_usage(@table.disk_usage)}456 N records: #{@table.size}457 N columns: #{@table.columns.size}458#{inspect_columns(@table.columns).chomp}459 INSPECTED460 end461 end462 class TokenizerTest < self463 def test_array464 Groonga::Schema.create_table("Users")465 @table = Groonga["Users"]466 assert_equal(inspected("(no key)"), report)467 end468 def test_no_tokenizer469 Groonga::Schema.create_table("Users",470 :type => :hash,471 :key_type => :short_text)472 @table = Groonga["Users"]473 assert_equal(inspected("(no tokenizer)"), report)474 end475 def test_have_tokenizer476 Groonga::Schema.create_table("Users",477 :type => :patricia_trie,478 :key_type => :short_text,479 :default_tokenizer => "TokenBigram")480 @table = Groonga["Users"]481 assert_equal(inspected("TokenBigram"), report)482 end483 private484 def inspected(inspected_tokenizer)485 <<-INSPECTED486#{@table.name}:487 ID: #{@table.id}488 Type: #{inspect_table_type(@table)}489 Key type: #{inspect_key_type(@table)}490 Tokenizer: #{inspected_tokenizer}491 Normalizer: #{inspect_normalizer(@table)}492 Path: <#{@table.path}>493 Total disk usage: #{inspect_sub_disk_usage(total_table_disk_usage(@table))}494 Disk usage: #{inspect_sub_disk_usage(@table.disk_usage)}495 N records: #{@table.size}496 N columns: #{@table.columns.size}497#{inspect_columns(@table.columns).chomp}498 INSPECTED499 end500 end501 class NormalizerTest < self502 def test_array503 Groonga::Schema.create_table("Users")504 @table = Groonga["Users"]505 assert_equal(inspected("(no key)"), report)506 end507 def test_no_normalizer508 Groonga::Schema.create_table("Users",509 :type => :hash,510 :key_type => :short_text)511 @table = Groonga["Users"]512 assert_equal(inspected("(no normalizer)"), report)513 end514 def test_have_normalizer515 Groonga::Schema.create_table("Users",516 :type => :patricia_trie,517 :key_type => :short_text,518 :normalizer => "NormalizerAuto")519 @table = Groonga["Users"]520 assert_equal(inspected("NormalizerAuto"), report)521 end522 private523 def inspected(inspected_normalizer)524 <<-INSPECTED525#{@table.name}:526 ID: #{@table.id}527 Type: #{inspect_table_type(@table)}528 Key type: #{inspect_key_type(@table)}529 Tokenizer: #{inspect_tokenizer(@table)}530 Normalizer: #{inspected_normalizer}531 Path: <#{@table.path}>532 Total disk usage: #{inspect_sub_disk_usage(total_table_disk_usage(@table))}533 Disk usage: #{inspect_sub_disk_usage(@table.disk_usage)}534 N records: #{@table.size}535 N columns: #{@table.columns.size}536#{inspect_columns(@table.columns).chomp}537 INSPECTED538 end539 end540 class NColumnsTest < self541 def test_no_columns542 Groonga::Schema.create_table("Users")543 @table = Groonga["Users"]544 assert_equal(inspected(0), report)545 end546 def test_have_columns547 Groonga::Schema.create_table("Users") do |table|548 table.short_text("name")549 table.int8("age")550 end551 @table = Groonga["Users"]552 assert_equal(inspected(2), report)553 end554 private555 def inspected(n_columns)556 <<-INSPECTED557#{@table.name}:558 ID: #{@table.id}559 Type: #{inspect_table_type(@table)}560 Key type: #{inspect_key_type(@table)}561 Tokenizer: #{inspect_tokenizer(@table)}562 Normalizer: #{inspect_normalizer(@table)}563 Path: <#{@table.path}>564 Total disk usage: #{inspect_sub_disk_usage(total_table_disk_usage(@table))}565 Disk usage: #{inspect_sub_disk_usage(@table.disk_usage)}566 N records: #{@table.size}567 N columns: #{n_columns}568#{inspect_columns(@table.columns).chomp}569 INSPECTED570 end571 end572 class ColumnsTest < self573 setup574 def setup_tables575 Groonga::Schema.create_table("Users") do |table|576 table.short_text("name")577 table.int8("age")578 end579 @table = Groonga["Users"]580 end581 def test_no_show_columns582 @options.show_columns = false583 assert_equal(<<-INSPECTED, report)584#{@table.name}:585 ID: #{@table.id}586 Type: #{inspect_table_type(@table)}587 Key type: #{inspect_key_type(@table)}588 Tokenizer: #{inspect_tokenizer(@table)}589 Normalizer: #{inspect_normalizer(@table)}590 Path: <#{@table.path}>591 Total disk usage: #{inspect_sub_disk_usage(total_table_disk_usage(@table))}592 Disk usage: #{inspect_sub_disk_usage(@table.disk_usage)}593 N records: #{@table.size}594 N columns: #{@table.columns.size}595 INSPECTED596 end597 end598 end599 class ColumnTest < self600 private601 def report602 output = StringIO.new603 reporter = create_reporter(output)604 reporter.send(:report_column, @column)605 output.string606 end607 class TypeTest < self608 def test_scalar_fix_size609 create_table do |table|610 table.int32("age")611 end612 assert_equal(inspected("scalar"), report)613 end614 def test_scalar_variable_size615 create_table do |table|616 table.short_text("name")617 end618 assert_equal(inspected("scalar"), report)619 end620 def test_vector621 create_table do |table|622 table.short_text("tags", :type => :vector)623 end624 assert_equal(inspected("vector"), report)625 end626 def test_index627 create_table do |table|628 end629 Groonga::Schema.create_table("Bookmarks") do |table|630 table.reference("user", "Users")631 end632 create_table do |table|633 table.index("Bookmarks.user")634 end635 assert_equal(inspected("index"), report)636 end637 private638 def create_table639 Groonga::Schema.create_table("Users") do |table|640 yield(table)641 end642 @table = Groonga["Users"]643 @column = @table.columns.first644 end645 def inspected(type)646 if type == "index"647 sources = @column.sources648 additional_info = " N sources: #{sources.size}\n"649 additional_info << " Sources:\n"650 source_names = sources.collect do |source|651 " Name: #{source.name}"652 end653 additional_info << source_names.join("\n")654 else655 additional_info = " Value type: #{@column.range.name}"656 end657 <<-INSPECTED658#{@column.local_name}:659 ID: #{@column.id}660 Type: #{type}661#{additional_info}662 Path: <#{@column.path}>663 Disk usage: #{inspect_sub_disk_usage(@column.disk_usage)}664 INSPECTED665 end666 end667 class SourceTest < self668 def test_key669 Groonga::Schema.create_table("Users",670 :type => :patricia_trie,671 :key_type => "ShortText") do |table|672 end673 Groonga::Schema.create_table("Terms",674 :type => :patricia_trie,675 :key_type => "ShortText",676 :default_tokenizer => "TokenBigram",677 :normalizer => "NormalizerAuto") do |table|678 table.index("Users._key")679 end680 @table = Groonga["Terms"]681 @column = @table.columns.first682 assert_equal(inspected(["Users._key"]), report)683 end684 private685 def inspected(source_names)686 inspected_sources = " N sources: #{source_names.size}\n"687 inspected_sources << " Sources:\n"688 source_names.each do |source_name|689 inspected_sources << " Name: #{source_name}\n"690 end691 <<-INSPECTED692#{@column.local_name}:693 ID: #{@column.id}694 Type: index695#{inspected_sources.chomp}696 Path: <#{@column.path}>697 Disk usage: #{inspect_sub_disk_usage(@column.disk_usage)}698 INSPECTED699 end700 end701 end702end...

Full Screen

Full Screen

loader.rb

Source:loader.rb Github

copy

Full Screen

...59 else60 raise ArgumentError, "position must be :before or :after"61 end62 _logger.debug do63 "add_component_search_path! #{path.inspect} #{opts.inspect}"64 end65 self66 end67 def add_component_directory! path68 path = Cabar.path_expand(path)69 return self if @component_directories.include? path70 return self if @component_directories_pending.include? path71 @component_directories_pending << path72 self73 end74 # Force loading of a component directory.75 def load_component! directory, opts = nil76 add_component_search_path!("@#{directory}", opts)77 end78 # Load components from the component_search_path79 # and component_directory queues.80 #81 # A queue is used because some components82 # may add component search paths during83 # loading, to implement recursive component repositories.84 #85 # cabar/plugin/core.rb is loaded here to support the "components" Facet for comp/ directories.86 def load_components!87 _logger.debug :"load_components!"88 plugin_manager.load_plugin! "#{Cabar.cabar_base_directory}/lib/ruby/cabar/plugin/core.rb"89 notify_observers(:before_load_components!)90 _scan_pending_directories!91 # Load each most recent component's plugins.92 load_most_recent_plugins!93 # Now that all components (and any plugins have been loaded),94 # the components can be fully configured.95 @component_configure_pending.cabar_each! do | c |96 c.configure!97 _logger.debug do98 "configure component #{c.inspect}"99 end100 end101 notify_observers(:after_load_components!)102 self103 end104 def _scan_pending_directories!105 path = nil106 dir = nil107 _logger.debug do 108 "_scan_pending_directories!"109 end110 # While there are still component paths to search,111 @component_search_path_pending.cabar_each! do | path |112 _logger.debug do113 " search path #{path.inspect}"114 end115 @component_search_path << path116 117 search_for_component_directories!(path).each do | dir |118 add_component_directory! dir119 end120 # While there are still components to load,121 @component_directories_pending.cabar_each! do | dir |122 @component_directories << dir123 _logger.debug do124 " component dir #{dir.inspect}"125 end126 # Create each component.127 _load_component! dir128 end129 end130 _logger.debug do 131 "_scan_pending_directories!: DONE"132 end133 rescue Exception => err134 raise Error.new('Loading components', 135 :error => err, 136 :directory => dir, 137 :pending_paths => @component_search_path_pending,138 :pending_directories => @component_directories_pending)139 end140 # Returns a list of all component directories.141 def search_for_component_directories! *path142 _logger.debug do143 "search_for_component_directories! #{path.inspect}"144 end145 # Find all */*/cabar.yml or */cabar.yml files.146 x = path.map do | p |147 # Handle '@foo/bar' as a direct reference to component foo/bar.148 p = p.dup149 if p.sub!(/^@/, '' )150 [ "#{p}/cabar.yml" ]151 else152 [ "#{p}/*/[01234567889]*/cabar.yml", "#{p}/*/std/cabar.yml", "#{p}/*/cabar.yml" ]153 end154 end.cabar_flatten_return!155 156 # Glob matching.157 x.map! do | f |158 Dir[f]159 end.cabar_flatten_return!160 161 # Take the directories.162 x.map! do | f |163 File.dirname(f)164 end165 166 # Unique.167 x = x.cabar_uniq_return!168 _logger.debug do169 "search_for_component_directories! #{path.inspect} => #{x.inspect}"170 end171 x172 end173 ##################################################################174 #175 # Returns a set of all available Components176 # found through the component_directories search path.177 #178 # The most recent component's plugins are loaded.179 def available_components180 unless @available_components181 @available_components = Cabar::Version::Set.new182 load_components!183 end184 @available_components185 end186 # Called when a component has been added.187 def add_available_component! c188 unless @available_components.include?(c)189 @available_components << c190 @component_configure_pending << c191 notify_observers(:available_component_added!, c)192 end193 end194 def inspect195 "#<#{self.class}:#{'0x%0x' % self.object_id}>"196 end197 198private199 # Helper method to create a Component.200 def create_component opts201 opts[:_loader] = self202 c = Component.factory.new opts203 c204 end205 def _parse_component_config directory, conf_file = nil206 raise TypeError, "main is not defined" unless Main === main207 conf_file ||= 208 File.join(directory, "cabar.yml")209 210 _logger.info do211 " loading #{conf_file.inspect}"212 end213 conf = configuration.read_config_file conf_file214 conf = conf['cabar']215 216 # Enabled?217 if conf['enabled'] != nil && ! conf['enabled']218 return nil219 end220 # Handle components.221 unless comps = conf['component']222 raise Error, "does not have a component definition"223 end224 unless Hash === comps225 comps = { }226 end227 # Infer component name/version from directory.228 infer_component_name comps, directory229 # Transform:230 #231 # component:232 # name: NAME233 # version: VERSION234 # ...235 # TO:236 #237 # component:238 # NAME:239 # version: VERSION240 # ...241 #242 name = nil243 if comps.size >= 2 && comps['name'] && comps['version']244 name = comps['name']245 comps.delete 'name'246 comps = { name => comps }247 end248 249 _logger.info do250 " loading #{conf_file.inspect}: DONE"251 end252 [ conf, comps, conf_file ]253 end254 # Returns the cabar Component with the greatest version.255 def cabar_component256 @cabar_component ||=257 available_components['cabar'].first || 258 (raise Error, "Cannot find cabar component.")259 end260 # Loads the plugins from the most recent version of each component.261 def load_most_recent_plugins!262 _logger.info do263 "loading plugins"264 end265 notify_observers(:before_load_plugins!)266 plugin_manager.load_plugin! "#{Cabar.cabar_base_directory}/lib/ruby/cabar/plugin/cabar.rb"267 available_components.most_recent.each do | comp |268 load_plugin_for_component! comp269 end270 # Associate all core or orphaned Plugins with Cabar itself.271 associate_orphaned_plugins! cabar_component272 notify_observers(:after_load_plugins!)273 _logger.info do274 "loading plugins: DONE"275 end276 self277 end278 def load_plugin_for_component! comp279 return if comp.plugins_status280 notify_observers(:before_load_plugin_for_component!, comp)281 default_component_save = Cabar::Plugin.default_component282 Cabar::Plugin.default_component = comp283 @component = comp284 @plugins = [ ]285 comp.plugins_status = :loading286 load_plugins! comp._config['plugin'], comp.name, comp.directory287 comp.plugins = @plugins288 comp.plugins_status = :loaded289 290 notify_observers(:after_load_plugin_for_component!, comp)291 ensure292 @component = @plugins = nil293 Cabar::Plugin.default_component = default_component_save294 end295 # Loads a component's plugins.296 # Use component name as the default Plugin name.297 def load_plugins! plugin, name, directory298 return unless plugin299 plugin = [ plugin ] unless Array === plugin300 301 default_name_save = Cabar::Plugin.default_name = name302 303 # Observe when plugins are installed.304 plugin_manager.add_observer(self, :plugin_installed, :plugin_installed!)305 306 plugin.each do | file |307 next unless file308 309 file = Cabar.path_expand(file, directory)310 311 plugin_manager.load_plugin! file312 end313 ensure314 Cabar::Plugin.default_name = default_name_save315 plugin_manager.delete_observer(self, :plugin_installed)316 end317 def plugin_manager318 main.plugin_manager319 end320 # Observer callback for associating Plugins with Components.321 def plugin_installed! plugin_manager, plugin322 _logger.debug do323 " plugin installed #{plugin.name.inspect} #{plugin.file.inspect}"324 end325 @plugins << plugin326 end327 def associate_orphaned_plugins! comp328 raise TypeError, "expected Component, given #{comp.class}" unless Component === comp329 plugin_manager.plugins.each do | p |330 p.component ||= comp331 end332 end333 def _load_component! directory, conf_file = nil334 # The component.335 comp = nil336 conf, comps, conf_file = _parse_component_config directory, conf_file337 return nil unless conf338 _logger.info do339 " loading #{conf_file}: DONE"340 end341 # Process each component definition.342 comps.each do | name, opts |343 # Overlay configuration.344 comp_config = 345 (x = configuration.config['component']) && 346 x['configure']347 comp_config ||= EMPTY_HASH348 comp_config = comp_config[name] || EMPTY_HASH349 # $stderr.puts "comp_config #{name.inspect} => #{comp_config.inspect}"350 opts.cabar_merge! comp_config351 # puts "comp opts #{name.inspect} => "; pp opts352 353 opts['name'] ||= name354 opts['directory'] ||= directory355 # opts['enabled'] = conf['enabled']356 opts[:_config_file] = conf_file357 # puts "comp opts #{name.inspect} => "; pp opts358 opts[:_loader] = self359 # opts[:resolver] = self # HUH: is this right?360 comp = create_component opts361 362 unless valid_string? comp.name363 raise Error, "component in #{directory.inspect} has no name" 364 end365 unless Version === comp.version366 raise Error, "component #{name.inspect} has no version #{comp.version.inspect}"367 end368 369 # Save config hash for later.370 comp._config = conf371 # Register component, if it's enabled.372 # Do early configuration (i.e.: handle "components" Facet comp/ directories).373 if comp.enabled?374 _logger.debug do375 " enabled #{conf_file.inspect}"376 end377 comp.configure_early!378 add_available_component! comp379 else380 _logger.info do 381 " component #{comp} disabled"382 end383 end384 _logger.info do385 " parse #{conf_file.inspect}: DONE"386 end387 comp388 end389 rescue Exception => err390 if comp391 comp._options[:enabled] = false392 end393 raise Error.new("in #{conf_file.inspect}: in #{self.class}", :error => err)394 end395 396 # Attempt to infer a component's name or version 397 # if not specified by the component's cabar.yml.398 # Plugins can register for :infer_component_name action via399 # add_observer.400 def infer_component_name comps, directory401 # Give plugins a chance.402 notify_observers(:infer_component_name, comps, directory)403 # Infer component name/version from directory name.404 unless comps['name'] && comps['version']405 case directory406 # name/version OR name-version407 when /\/([a-z_][^\/]*)[\/-]([0-9]+(\.[0-9]+)*)$/i...

Full Screen

Full Screen

test_plugins.rb

Source:test_plugins.rb Github

copy

Full Screen

...4class ATestPlugin < GemPlugin::Plugin "/stuff"5end6class First < GemPlugin::Plugin "/commands"7 def initialize(options = {})8 puts "First with options: #{options.inspect}"9 end10end11class Second < GemPlugin::Plugin "/commands"12 def initialize(options = {})13 puts "Second with options: #{options.inspect}"14 end15end16class Last < GemPlugin::Plugin "/commands"17 def initialize(options = {})18 puts "Last with options: #{options.inspect}"19 end20end21class PluginTest < Test::Unit::TestCase22 def setup23 @pmgr = Manager.instance24 @pmgr.load({"rails" => EXCLUDE})25 @categories = ["/commands"]26 @names = ["/first", "/second", "/last", "/atestplugin"]27 end28 def test_load_plugins29 puts "#{@pmgr.plugins.inspect}"30 @pmgr.plugins.each {|cat,plugins|31 plugins.each do |n,p|32 puts "TEST: #{cat}#{n}"33 end34 }35 @pmgr.load36 @pmgr.plugins.each do |cat,plugins|37 plugins.each do |n,p|38 STDERR.puts "#{cat}#{n}"39 plugin = @pmgr.create("#{cat}#{n}", options={"name" => p})40 end41 end42 end43 def test_similar_uris...

Full Screen

Full Screen

inspect

Using AI Code Generation

copy

Full Screen

11.rb:9:in `<main>': uninitialized constant Plugins::Plugin1 (NameError)2class ClassName; end3class ClassName; end4class Class1; end5class Class2; end6class Class3; end

Full Screen

Full Screen

inspect

Using AI Code Generation

copy

Full Screen

1Plugins.load('hello')2Plugins.load('goodbye')3Plugins.load('hello')4Plugins.load('goodbye')5Plugins.load('goodbye')6Plugins.load('hello')7Plugins.load('goodbye')8Plugins.load('hello')9Plugins.load('goodbye')10Plugins.load('hello')11Plugins.load('goodbye')12Plugins.load('hello

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Inspec_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful