stashify 1.0.4 → 2.0.0

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
  SHA256:
3
- metadata.gz: ac39c7eaa7f0a6e924497457841cc2087d34cacda4d400d32d3fa3e95965de69
4
- data.tar.gz: fcb7cef63717efdbcb91eb0e668282352f62581e3205423bb16cfb4be0077210
3
+ metadata.gz: 72261627ef443188786450d298ba1b7223c0297466b7991979ab34aa3b348bff
4
+ data.tar.gz: 9544398bc63888267cafbb8ead584340fb7b2597a526a8b9e04adf2672fe1c9b
5
5
  SHA512:
6
- metadata.gz: 6e592aeefb27cd272449dc897ce23a59abd2f298f115280b5c5eac26d9b448c6169cb29280350ba4ab3f1c19746779b976c54a85aa95ca11bc61c20d451b0a3a
7
- data.tar.gz: 15ed987a91e39127836c08b7a9f4099aab4a2b16b804e3f944f987ce50b62ed9a65516032e99c27cd10efc65f177840b66bde5e19b779cf6f053f34453a5c967
6
+ metadata.gz: e143737520b394cf9e5a652a34cb018f1a351bc9d0fe9ff2b5e6a4a8940f8de6b20e1a33a28ac3d42ab894d885b133fe64ebc2172889feaa70f5298e326407a9
7
+ data.tar.gz: 73e3b1d0b25a2ed60d0654dadac1b65b8ee44b5359f5100ad2019e81b9fd79dd6660d478edb0d64a22198a3f2f355d7cdf2dd6442da04b022da62edd2653905f
data/.reek.yml CHANGED
@@ -13,3 +13,7 @@ detectors:
13
13
  FeatureEnvy:
14
14
  exclude:
15
15
  - Stashify::Directory::Local#write
16
+
17
+ ControlParameter:
18
+ exclude:
19
+ - Stashify::Directory#initialize
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stashify (1.0.4)
4
+ stashify (1.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -6,13 +6,6 @@ require "stashify/directory"
6
6
  module Stashify
7
7
  class Directory
8
8
  class Local < Stashify::Directory
9
- attr_reader :path
10
-
11
- def initialize(path)
12
- @path = path
13
- super(name: ::File.basename(path))
14
- end
15
-
16
9
  def write_directory(directory)
17
10
  FileUtils.mkdir(path_of(directory.name))
18
11
  super
@@ -23,24 +16,20 @@ module Stashify
23
16
  end
24
17
 
25
18
  def delete(name)
26
- path = ::File.join(@path, name)
27
- if ::File.directory?(path)
28
- FileUtils.rm_r(path)
19
+ name_path = ::File.join(path, name)
20
+ if ::File.directory?(name_path)
21
+ FileUtils.rm_r(name_path)
29
22
  else
30
- ::File.delete(path)
23
+ ::File.delete(name_path)
31
24
  end
32
25
  end
33
26
 
34
27
  def files
35
- Dir.entries(@path).grep_v(/^[.][.]?$/).map do |file_name|
28
+ Dir.entries(path).grep_v(/^[.][.]?$/).map do |file_name|
36
29
  find(::File.basename(file_name))
37
30
  end
38
31
  end
39
32
 
40
- def ==(other)
41
- @path == other.path
42
- end
43
-
44
33
  private
45
34
 
46
35
  def file?(name)
@@ -48,7 +37,7 @@ module Stashify
48
37
  end
49
38
 
50
39
  def file(name)
51
- Stashify::File::Local.new(path_of(name))
40
+ Stashify::File::Local.new(path: path_of(name))
52
41
  end
53
42
 
54
43
  def directory?(name)
@@ -56,11 +45,7 @@ module Stashify
56
45
  end
57
46
 
58
47
  def directory(name)
59
- Stashify::Directory::Local.new(path_of(name))
60
- end
61
-
62
- def path_of(name)
63
- ::File.join(@path, name)
48
+ Stashify::Directory::Local.new(path: path_of(name))
64
49
  end
65
50
  end
66
51
  end
@@ -2,10 +2,13 @@
2
2
 
3
3
  module Stashify
4
4
  class Directory
5
- attr_reader :name, :files
5
+ attr_reader :name, :files, :path
6
6
 
7
- def initialize(name:, files: [])
8
- @name = name
7
+ def initialize(name: nil, path: nil, files: [])
8
+ raise StandardError, "name or path must be defined" unless name || path
9
+
10
+ @path = path
11
+ @name = name || ::File.basename(path)
9
12
  @files = files
10
13
  end
11
14
 
@@ -29,5 +32,19 @@ module Stashify
29
32
  subdir = self.directory(directory.name)
30
33
  directory.files.each { |file| subdir.write(file) }
31
34
  end
35
+
36
+ def ==(other)
37
+ files == other.files
38
+ end
39
+
40
+ def eql?(other)
41
+ self.class == other.class && name == other.name && path == other.path
42
+ end
43
+
44
+ private
45
+
46
+ def path_of(name)
47
+ ::File.join(path, name)
48
+ end
32
49
  end
33
50
  end
@@ -5,13 +5,8 @@ require "stashify/file"
5
5
  module Stashify
6
6
  class File
7
7
  class Local < Stashify::File
8
- def initialize(path)
9
- @path = path
10
- super(name: ::File.basename(path), contents: nil)
11
- end
12
-
13
8
  def contents
14
- ::File.read(@path)
9
+ ::File.read(path)
15
10
  end
16
11
  end
17
12
  end
data/lib/stashify/file.rb CHANGED
@@ -4,12 +4,14 @@ require "stashify"
4
4
 
5
5
  module Stashify
6
6
  class File
7
- attr_reader :name, :contents
7
+ attr_reader :name, :path, :contents
8
8
 
9
- def initialize(name:, contents: "")
10
- raise Stashify::InvalidFile, "Name '#{name}' contains a /" if name =~ %r{/}
9
+ def initialize(name: nil, path: nil, contents: "")
10
+ raise StandardError, "name or path must be defined" unless name || path
11
+ raise Stashify::InvalidFile, "Name '#{name}' contains a /" if name && name =~ %r{/}
11
12
 
12
- @name = name
13
+ @path = path
14
+ @name = name || ::File.basename(path)
13
15
  @contents = contents
14
16
  end
15
17
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stashify
4
- VERSION = "1.0.4"
4
+ VERSION = "2.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stashify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lambda Null
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-25 00:00:00.000000000 Z
11
+ date: 2023-03-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides an abstraction to various services (local filesystem, S3, etc)
14
14
  email: