dis 1.0.3 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca1ddbb8f8cbce08f246eb2ae764fc1f330cee7b
4
- data.tar.gz: 0faed0087f940954495eb77e994e78bc07b4f9b1
3
+ metadata.gz: 835c04f15f51b3e319654d2a8040df778c62cc8a
4
+ data.tar.gz: 2dee85c2af96d2804140d449a79e1d43fc3da22a
5
5
  SHA512:
6
- metadata.gz: f4a242e9bf376396a498def8cd1cd457bb5e35b680781cc337faef9d57e238c851f1ddead2417fa6221da4c89130b5672990565d026b3b7f328e47cfcc8ef1a3
7
- data.tar.gz: f811ffaf3e73c76e92df930ad03debd766da58d524d0bc2e929c6ba771a3e59b1167c385a2eab4469fd538a32d95be2edfa1f35c896b60b95bfe3a812235b95f
6
+ metadata.gz: b1f15973ebba3a27e077c3cbcfc779d3e42be633663c5fe1bc64b4662ac37af18da246aac11644e20303b440b649aa53021a5aeadfd284f1b75961c6a1a22ced
7
+ data.tar.gz: dd16af7aacf26faeeaf9052acc7e7ca2a91df3c2b9ed4b526cbb7b4b85b155aa1e024e00f9f06c79ca890a0a556253ca353e3639e0849f90fbedada66c545417
data/lib/dis.rb CHANGED
@@ -4,6 +4,8 @@ require "digest/sha1"
4
4
  require "fog/core"
5
5
  require "fog/local/storage"
6
6
  require "active_job"
7
+ require "pmap"
8
+ require "dis/engine"
7
9
  require "dis/errors"
8
10
  require "dis/jobs"
9
11
  require "dis/layer"
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ module Dis
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -125,6 +125,13 @@ module Dis
125
125
  delete!(type, hash)
126
126
  end
127
127
 
128
+ # Returns a name for the layer.
129
+ #
130
+ # layer.name # => "Fog::Storage::Local::Real/development"
131
+ def name
132
+ "#{connection.class.name}/#{path}"
133
+ end
134
+
128
135
  private
129
136
 
130
137
  def default_options
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Dis
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.4"
5
5
  end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ namespace :dis do
4
+ desc "Check stuff"
5
+ task consistency_check: :environment do
6
+ unless ENV["MODELS"]
7
+ puts "Usage: #{$PROGRAM_NAME} dis:consistency_check " \
8
+ "MODELS=Avatar,Document"
9
+ exit
10
+ end
11
+
12
+ models = ENV["MODELS"].split(",").map(&:strip).map(&:constantize)
13
+
14
+ models.each do |model|
15
+ puts "-- #{model.name} --"
16
+
17
+ content_hash_attr = model.dis_attributes[:content_hash]
18
+ objects = model
19
+ .select(content_hash_attr)
20
+ .uniq
21
+ .map { |r| r.send(content_hash_attr) }
22
+
23
+ puts "Unique objects: #{objects.length}"
24
+
25
+ Dis::Storage.layers.each do |layer|
26
+ existing = objects
27
+ .pmap { |hash| [hash, layer.exists?(model.dis_type, hash)] }
28
+ .select(&:last)
29
+ .map(&:first)
30
+ missing = objects - existing
31
+ puts "#{layer.name}: #{existing.length} (#{missing.length} missing)"
32
+
33
+ puts "Missing objects:\n#{missing.inspect}" if missing.any?
34
+ end
35
+
36
+ puts
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.26.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pmap
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.2
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: sqlite3
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +91,7 @@ files:
77
91
  - MIT-LICENSE
78
92
  - README.md
79
93
  - lib/dis.rb
94
+ - lib/dis/engine.rb
80
95
  - lib/dis/errors.rb
81
96
  - lib/dis/jobs.rb
82
97
  - lib/dis/jobs/delete.rb
@@ -86,7 +101,6 @@ files:
86
101
  - lib/dis/model.rb
87
102
  - lib/dis/model/class_methods.rb
88
103
  - lib/dis/model/data.rb
89
- - lib/dis/sparse_layer.rb
90
104
  - lib/dis/storage.rb
91
105
  - lib/dis/validations.rb
92
106
  - lib/dis/validations/data_presence.rb
@@ -94,6 +108,7 @@ files:
94
108
  - lib/rails/generators/dis/install/install_generator.rb
95
109
  - lib/rails/generators/dis/install/templates/initializer.rb
96
110
  - lib/rails/generators/dis/model/model_generator.rb
111
+ - lib/tasks/dis.rake
97
112
  homepage: https://github.com/elektronaut/dis
98
113
  licenses:
99
114
  - MIT
@@ -1,98 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Dis
4
- # = Dis SparseLayer
5
- #
6
- # A special case of Dis::Layer intended to be sparsely populated.
7
- # Can be configured with a size limit, objects that have been transferred
8
- # to other layers will be evicted based on a Least Recently Used basis.
9
- #
10
- # ==== Example
11
- #
12
- # Dis::SparseLayer.new(
13
- # Fog::Storage.new({
14
- # provider: 'Local',
15
- # local_root: Rails.root.join('db', 'dis')
16
- # }),
17
- # path: Rails.env,
18
- # limit: 10.gigabytes
19
- # )
20
- class SparseLayer < Layer
21
- def initialize(connection, options={})
22
- super
23
- @limit = options[:limit]
24
- end
25
-
26
- def limit?
27
- @limit ? true : false
28
- end
29
-
30
- def store(type, hash, file)
31
- super.tap do
32
- update_timestamp(type, hash)
33
- end
34
- end
35
-
36
- def get(type, hash)
37
- super.tap do |result|
38
- update_timestamp(type, hash) if result
39
- end
40
- end
41
-
42
- def delete(type, hash)
43
- super.tap do
44
- delete_timestamp(type, hash)
45
- end
46
- end
47
-
48
- private
49
-
50
- def delete_timestamp(type, path)
51
- return false unless timestamp_exists?(type, path)
52
- get_timestamp(type, path).destroy
53
- end
54
-
55
- def get_timestamp(type, hash)
56
- if dir = directory(type, hash)
57
- dir.files.get(timestamp_path(type, hash))
58
- end
59
- end
60
-
61
- def outdated_timestamp?(timestamp)
62
- !timestamp || timestamp < 5.minutes.ago
63
- end
64
-
65
- def read_timestamp(type, hash)
66
- if timestamp = get_timestamp(type, hash)
67
- DateTime.parse(timestamp.body)
68
- end
69
- end
70
-
71
- def timestamp_exists?(type, hash)
72
- if (directory(type, hash) &&
73
- directory(type, hash).files.head(timestamp_path(type, hash)))
74
- true
75
- else
76
- false
77
- end
78
- end
79
-
80
- def timestamp_path(type, hash)
81
- key_component(type, hash) + ".timestamp"
82
- end
83
-
84
- def update_timestamp(type, hash)
85
- if outdated_timestamp?(read_timestamp(type, hash))
86
- write_timestamp(type, hash)
87
- end
88
- end
89
-
90
- def write_timestamp(type, hash)
91
- directory!(type, hash).files.create(
92
- key: timestamp_path(type, hash),
93
- body: DateTime.now.to_s,
94
- public: public?
95
- )
96
- end
97
- end
98
- end