sagan_crafter 0.3.0 → 0.4.0

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: 0a1b504c92f2ab3809f4b21923a1320f9d2e6dc3
4
- data.tar.gz: 2d72d3a051d6a190a4b4470e6196b75ad7733d84
3
+ metadata.gz: f1d7bb24c4114f2d7c6d33e69d7408d1eeb77a07
4
+ data.tar.gz: 58ab491faa2df6568dbe94a1953e37af47d39311
5
5
  SHA512:
6
- metadata.gz: bbf70fe464fcbfc296c4936411e5632486b1aaa29222fe8fe9122b9b0f9cf6f9af6892144d9f971a062feeacc8794c9b12e75330ae6819cc5061cb3ad30966a1
7
- data.tar.gz: 39e7666c657d3d417e8ebf44fa33e5a4aea9f589008dde47f11d1c3cb713c75e7954e08b68c880ce68d3a7f15b792587208bbae814571837abea82d7a09b379e
6
+ metadata.gz: a72b348e2adf6bd76c338916b977079c4a8acb2275918771bf0f86a98b7b9a91d1fb8ee819ae2545b85c1d57dd149a380524f585efd904a929941e3475b77bb6
7
+ data.tar.gz: 56ff929ce63782ad216b8bff3c134709fb2c4650833edf0bf0aa605e0009e221c9968bdce63f40d43f53e3c2aa32020a2d91d3920ae5a09bd8c7e3c7a8b4fe81
@@ -17,16 +17,21 @@ module SaganCrafter
17
17
 
18
18
  attr_reader :rule_collection
19
19
 
20
- def initialize(factory)
21
- @db = connect(SaganCrafter::Settings.sql_file_location)
20
+ def initialize(factory, existing_db_connection = nil)
21
+ if existing_db_connection
22
+ @db = existing_db_connection
23
+ else
24
+ @db = connect(SaganCrafter::Settings.sql_file_location)
25
+ end
22
26
  @factory = factory
23
27
  @db.results_as_hash = true
24
28
  @rule_collection = []
25
29
  end
26
30
 
27
31
  def size
28
- count = db.get_first_value("select count(DISTINCT name) from #{SaganCrafter::Settings.sql_table_name}")
29
- puts "#{}count(*): #{count}"
32
+ count = @db.get_first_value("select count(DISTINCT name) from #{SaganCrafter::Settings.sql_table_name}")
33
+ puts "count(*): #{count}" if SaganCrafter::Settings.verbose
34
+ count
30
35
  end
31
36
 
32
37
  def validate!
@@ -3,5 +3,6 @@ module SaganCrafter
3
3
  class CustomError < StandardError; end
4
4
  class UnknownDBSchemaError < StandardError; end
5
5
  class UnknownFactoryError < StandardError; end
6
+ class TemplateError < StandardError; end
6
7
 
7
8
  end
@@ -2,9 +2,10 @@ module SaganCrafter
2
2
  class Ruleset
3
3
  attr_reader :rules
4
4
 
5
- def initialize(rule_sources)
5
+ def initialize(rule_sources, existing_connection=nil)
6
6
  @rules_builders = []
7
7
  @rules = []
8
+ @connection = existing_connection
8
9
  rule_sources.each do |source|
9
10
  @rules << new_rule_source(source)
10
11
  end
@@ -15,12 +16,16 @@ module SaganCrafter
15
16
  @rules.to_s
16
17
  end
17
18
 
19
+ def new_rule_source(source)
20
+ raise TemplateError, "new_rule_source called on template class Ruleset"
21
+ end
22
+
18
23
  end
19
24
 
20
25
  class FQDNRuleset < Ruleset
21
26
  def new_rule_source(source)
22
27
  puts "#[sagan-crafter] #{self.class} - #{source}" if SaganCrafter::Settings.verbose
23
- printer = SaganCrafter::Backends::SQLite.new(SaganCrafter::Factory::FQDNlogger.new )
28
+ printer = SaganCrafter::Backends::SQLite.new(SaganCrafter::Factory::FQDNlogger.new, @connection)
24
29
  printer.validate!
25
30
  return printer.build
26
31
  end
@@ -29,7 +34,7 @@ module SaganCrafter
29
34
  class IPRuleset < Ruleset
30
35
  def new_rule_source(source)
31
36
  puts "#[sagan-crafter] #{self.class} - #{source}" if SaganCrafter::Settings.verbose
32
- printer = SaganCrafter::Backends::SQLite.new(SaganCrafter::Factory::IPlogger.new )
37
+ printer = SaganCrafter::Backends::SQLite.new(SaganCrafter::Factory::IPlogger.new, @connection)
33
38
  printer.validate!
34
39
  return printer.build
35
40
  end
@@ -1,3 +1,3 @@
1
1
  module SaganCrafter
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sagan_crafter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shadowbq