Class: FileTreeProfiler::Export::SQL
- Inherits:
-
Object
- Object
- FileTreeProfiler::Export::SQL
- Defined in:
- lib/file_tree_profiler/export/sql.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#profile(db, dir_file) ⇒ Object
readonly
Returns the value of attribute profile.
-
#root_id ⇒ Object
readonly
Returns the value of attribute root_id.
Instance Method Summary collapse
- #create_schema(db) ⇒ Object
-
#initialize(profile, config) ⇒ SQL
constructor
A new instance of SQL.
- #insert_file(db, file) ⇒ Object
Constructor Details
#initialize(profile, config) ⇒ SQL
Returns a new instance of SQL.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/file_tree_profiler/export/sql.rb', line 7 def initialize(profile, config) @profile = profile @config = config Sequel.connect(config) do |db| create_schema db @root_id = db[:roots].insert(:path => profile.root.path) profile db, profile.root end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/file_tree_profiler/export/sql.rb', line 6 def config @config end |
#profile(db, dir_file) ⇒ Object (readonly)
Returns the value of attribute profile.
6 7 8 |
# File 'lib/file_tree_profiler/export/sql.rb', line 6 def profile @profile end |
#root_id ⇒ Object (readonly)
Returns the value of attribute root_id.
6 7 8 |
# File 'lib/file_tree_profiler/export/sql.rb', line 6 def root_id @root_id end |
Instance Method Details
#create_schema(db) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/file_tree_profiler/export/sql.rb', line 18 def create_schema db db.create_table :roots do primary_key :id String :path, :unique => true end unless db.table_exists? :roots db.create_table :files do primary_key :id foreign_key :root_id String :type String :name String :path String :relative_path String :checksum Boolean :empty Integer :size index :type index [:root_id, :path], :unique => true index :checksum end unless db.table_exists? :files end |
#insert_file(db, file) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/file_tree_profiler/export/sql.rb', line 39 def insert_file db, file db[:files].insert( :root_id => root_id, :type => (file.class == DirFile ? 'dir' : 'data'), :path => file.path, :relative_path => file.relative_path, :name => file.name, :checksum => file.checksum, :empty => file.empty?, :size => file.size) end |