mir 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,9 @@ module Mir
13
13
 
14
14
  # Returns a databse object used to connect to the indexing database
15
15
  #
16
- # @param [String] the absolute path of the directory to be synchronized
17
- # @param [Hash] database configuration settings. See ActiveRecord#Base::establish_connection
16
+ # @param sync_path [String] the absolute path of the directory to be synchronized
17
+ # @param connection_params [Hash] database configuration settings. See ActiveRecord#Base::establish_connection
18
+ # @return [Mir::Index]
18
19
  def initialize(sync_path, connection_params)
19
20
  @sync_path = sync_path
20
21
  @connection_params = connection_params
@@ -25,8 +26,9 @@ module Mir
25
26
  #
26
27
  # Creates necessary database and tables if this is the first time connecting
27
28
  #
28
- # @option opts [Boolean] :verbose Enable on ActiveRecord reporting
29
- # @option opts [Boolean] :force_flush Rebuild index no matter what
29
+ # @option options [Boolean] :verbose Enable on ActiveRecord reporting
30
+ # @option options [Boolean] :force_flush Rebuild index no matter what
31
+ # @return [void]
30
32
  def setup(options = {})
31
33
  options[:force_flush] ||= false
32
34
  options[:verbose] ||= false
@@ -45,6 +47,7 @@ module Mir
45
47
  ##
46
48
  # Scans the synchronization path and evaluates whether a resource has changed
47
49
  # since the last index or is new and needs to be added to the index.
50
+ # @return [void]
48
51
  def update
49
52
  Mir.logger.info "Updating backup index for '#{sync_path}'"
50
53
  Models::AppSetting.last_indexed_at = @last_indexed_at = DateTime.now
@@ -70,11 +73,14 @@ module Mir
70
73
  # Returns any files not present since the last re-indexing. This is useful
71
74
  # for finding files that have been deleted post-index.
72
75
  #
73
- # @return [Mir::Models::Resource]
76
+ # @return [Array, Mir::Models::Resource]
74
77
  def orphans
75
78
  Models::Resource.not_indexed_on(last_indexed_at)
76
79
  end
77
80
 
81
+ ##
82
+ # The date at whish the backup path was last indexed
83
+ # @return [DateTime]
78
84
  def last_indexed_at
79
85
  @last_indexed_at ||= Models::AppSetting.last_indexed_at
80
86
  end
@@ -82,17 +88,23 @@ module Mir
82
88
 
83
89
  ##
84
90
  # Removes any files from the index that are no longer present locally
91
+ # @return [void]
85
92
  def clean!
86
93
  Models::Resource.delete_all_except(last_indexed_at)
87
94
  end
88
95
 
89
96
  private
97
+ ##
90
98
  # Returns the path of a file relative to the backup directory
99
+ # @param file [String] the absolute path name of the file
100
+ # @return [String] the path of the file relative to the stored backup path
91
101
  def relative_path(file)
92
102
  File.absolute_path(file).gsub(sync_path,'')
93
103
  end
94
104
 
105
+ ##
95
106
  # Regenerates the file system index for the backup directory
107
+ # @return [void]
96
108
  def rebuild
97
109
  tables.each { |t| ActiveRecord::Migration.drop_table(t.table_name) if t.table_exists? }
98
110
  ActiveRecord::Migration.drop_table(:schema_migrations) if @connection.table_exists? :schema_migrations
@@ -102,7 +114,8 @@ module Mir
102
114
 
103
115
 
104
116
  ##
105
- # TODO: no reason to lazy load these activemodels
117
+ # Loads ActiveRecord tables
118
+ # @todo no reason to lazy load these activemodels
106
119
  def load_tables
107
120
  @tables = []
108
121
  models = File.join(File.dirname(__FILE__), "models", "*.rb")
@@ -115,12 +128,16 @@ module Mir
115
128
  end
116
129
  end
117
130
 
131
+ ##
118
132
  # Returns the activerecord classes for each table used by the application
133
+ # @return [Array, Class]
119
134
  def tables
120
135
  @tables
121
136
  end
122
137
 
123
- # Checks whether any of the tables required by the applicaiton exist
138
+ ##
139
+ # Checks whether any of the tables required by the application exist
140
+ # @return [Boolean]
124
141
  def tables_created?
125
142
  tables.any? { |t| t.table_exists? }
126
143
  end
@@ -1,9 +1,14 @@
1
1
  require 'logger'
2
2
 
3
3
  module Mir
4
+ # Assigns a global logger
5
+ # @param logger [Logger]
4
6
  def self.logger=(logger)
5
7
  @@logger = logger
6
8
  end
9
+
10
+ # Returns the global logger instance
11
+ # @return [Logger]
7
12
  def self.logger
8
13
  @@logger
9
14
  end
@@ -10,7 +10,7 @@ module Mir
10
10
  # Builds a resource for the backup index from a file
11
11
  # @param [File] a file object
12
12
  # @param [String] the name of the file on the remote disk
13
- # @returns [Resource] a new Resource instance that with a queued status
13
+ # @return [Resource] a new Resource instance that with a queued status
14
14
  def self.create_from_file_and_name(file, name)
15
15
  is_dir = File.directory?(file)
16
16
  create(:filename => name,
@@ -41,9 +41,11 @@ module Mir
41
41
  chunked_groups(qry, response_size) { |chunk| yield chunk }
42
42
  end
43
43
 
44
+ ##
44
45
  # Returns groups of file resources ordered by name
46
+ #
45
47
  # @param [Integer] the number of records to return per chunk
46
- # @yields [Array] instances of Models::Resource
48
+ # @yield [Array] instances of Models::Resource
47
49
  def self.ordered_groups(group_size = 10)
48
50
  qry = lambda { Resource.order(:filename) }
49
51
  chunked_groups(qry, group_size) { |chunk| yield chunk }
@@ -76,7 +78,7 @@ module Mir
76
78
  end
77
79
 
78
80
  # Whether the item can be synchronized to a remote disk
79
- # @returns [Boolean] true when the resource is not a directory
81
+ # @return [Boolean] true when the resource is not a directory
80
82
  def synchronizable?
81
83
  !is_directory?
82
84
  end
@@ -3,21 +3,26 @@ module Mir
3
3
 
4
4
  # Generates filename for a split file
5
5
  # filename_with_sequence("foobar.txt", 23) => foobar.txt.00000023
6
- # @param [String] filename
7
- # @param [Integer] the sequence number
6
+ # @param name [String] filename
7
+ # @param seq [Integer] the sequence number
8
+ # @return [String]
8
9
  def self.filename_with_sequence(name, seq)
9
10
  [name, ".", "%08d" % seq].join
10
11
  end
11
12
 
13
+ # Attempts to create the directory path specified
14
+ # @param path [String] the path to create
15
+ # @return [Dir]
12
16
  def self.try_create_dir(path)
13
17
  Dir.mkdir(path) unless Dir.exist?(path)
14
18
  Dir.new(path)
15
19
  end
16
20
 
17
21
  # Splits a file into pieces that may be reassembled later
18
- # @param [File or String] File to be split
22
+ # @param [File|String] File to be split
19
23
  # @param [Integer] the number of bytes per each chunked file
20
24
  # @param [String] where the split files should be stored
25
+ # @return [void]
21
26
  def self.split_file(file, chunk_size, dest)
22
27
  try_create_dir(dest) unless Dir.exist?(dest)
23
28
 
@@ -37,6 +42,7 @@ module Mir
37
42
  # Recombines a file from pieces
38
43
  # @param [String] the directory that holds the split files
39
44
  # @param [String] the path to the assembled file
45
+ # @return [void]
40
46
  def self.recombine(source_dir, dest)
41
47
  parts = Dir.glob(File.join(source_dir, "*"))
42
48
  open(File.expand_path(dest), "wb") do |file|
@@ -1,5 +1,5 @@
1
1
  module Mir
2
- VERSION = [0,1,4]
2
+ VERSION = [0,1,5]
3
3
 
4
4
  def self.version
5
5
  VERSION.join('.')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mir
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nate Miller
@@ -98,6 +98,35 @@ files:
98
98
  - bin/mir
99
99
  - db/migrate/001_create_app_settings.rb
100
100
  - db/migrate/002_create_resources.rb
101
+ - doc/Mir.html
102
+ - doc/Mir/Application.html
103
+ - doc/Mir/Config.html
104
+ - doc/Mir/Disk.html
105
+ - doc/Mir/Disk/Amazon.html
106
+ - doc/Mir/Disk/IncompleteTransmission.html
107
+ - doc/Mir/Disk/MultiPartFile.html
108
+ - doc/Mir/Disk/RemoteFileNotFound.html
109
+ - doc/Mir/Index.html
110
+ - doc/Mir/Models.html
111
+ - doc/Mir/Models/AppSetting.html
112
+ - doc/Mir/Models/Resource.html
113
+ - doc/Mir/Options.html
114
+ - doc/Mir/UndefinedConfigValue.html
115
+ - doc/Mir/Utils.html
116
+ - doc/_index.html
117
+ - doc/class_list.html
118
+ - doc/css/common.css
119
+ - doc/css/full_list.css
120
+ - doc/css/style.css
121
+ - doc/file.README.html
122
+ - doc/file_list.html
123
+ - doc/frames.html
124
+ - doc/index.html
125
+ - doc/js/app.js
126
+ - doc/js/full_list.js
127
+ - doc/js/jquery.js
128
+ - doc/method_list.html
129
+ - doc/top-level-namespace.html
101
130
  - lib/mir.rb
102
131
  - lib/mir/application.rb
103
132
  - lib/mir/config.rb