activefolder 0.0.5 → 1.0.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: 020e30e40612918e0063d5fa36fb3aff3c293eed
4
- data.tar.gz: 8e382664812b53c6ec4d315d9d43096e4a62bbb4
3
+ metadata.gz: d723e1b9eb722d530100fd75e13a97d744dd2e52
4
+ data.tar.gz: 546326b52d4274cbe274f6584634ed0856b92d0c
5
5
  SHA512:
6
- metadata.gz: c1a8ef1fc3d7553f8c3f6164faa1049e880efa319271ba21e6a49b3aa74e580354debd83e0c539fb950af8adb61be85e200eb8c3b3577fc8d8e8d616f8d346e4
7
- data.tar.gz: 552e0b30ee18334dbd48092dbbaacb074661e7f546235ebf2c141d6d259dc3b668d24ad3d75d77ce9a7582d733f4f2e712cf4657815caae7383761cdb066fb26
6
+ metadata.gz: 24c74a9e783e9eae1507936258a53f6d8807d012c3a88d2a870aef9940a5d99c80b96498c878a790e891102875e6056bd37b27d3c5d9cf9f0d5f337dbb888008
7
+ data.tar.gz: 439e64fc90e91311a24f5779130e0f0023e98a13b3d249b94b8c278d25a39d70efb2935878782ed46143d82014addaa3f7075b17fec0559681eaad1adceed516
@@ -1,13 +1,14 @@
1
1
  require 'ostruct'
2
2
 
3
3
  require 'active_folder/model/traits/persistence'
4
- require 'active_folder/model/traits/has_belongs'
4
+ require 'active_folder/model/traits/relation'
5
+ require 'active_folder/model/traits/collection'
5
6
  require 'active_folder/model/errors'
6
7
 
7
8
  module ActiveFolder
8
9
  class Base < OpenStruct
9
10
  include Model::Traits::Persistence
10
- include Model::Traits::HasBelongs
11
+ include Model::Traits::Relation
11
12
  extend Model::Traits::Collection
12
13
 
13
14
  class << self
@@ -33,6 +33,12 @@ module ActiveFolder
33
33
  raise SystemError.new(e)
34
34
  end
35
35
 
36
+ def del(path:)
37
+ FileUtils.rm_r full_path(path)
38
+ rescue SystemCallError => e
39
+ raise SystemError.new(e)
40
+ end
41
+
36
42
  private
37
43
 
38
44
  def full_path(path)
@@ -22,6 +22,10 @@ module ActiveFolder
22
22
  adapter.glob(**args)
23
23
  end
24
24
 
25
+ def del(**args)
26
+ adapter.del(**args)
27
+ end
28
+
25
29
  def connection
26
30
  @connection
27
31
  end
@@ -9,10 +9,6 @@ module ActiveFolder
9
9
  def root_path
10
10
  @config.root_path
11
11
  end
12
-
13
- def current_path
14
- Dir.pwd
15
- end
16
12
  end
17
13
  end
18
14
  end
@@ -8,10 +8,8 @@ module ActiveFolder
8
8
  @config = config
9
9
  end
10
10
 
11
- def current_path; Dir.pwd end
12
-
13
11
  def root_path
14
- rugged.discover(current_path)
12
+ rugged.discover(Dir.pwd)
15
13
  rescue Rugged::RepositoryError => e
16
14
  raise SystemError.new(e)
17
15
  end
@@ -16,7 +16,11 @@ module ActiveFolder
16
16
 
17
17
  def create(args, &block)
18
18
  instance = build(args, &block);
19
- instance.save!; instance
19
+ instance.save; instance
20
+ end
21
+
22
+ def destroy_all
23
+ all.each { |element| element.destroy }
20
24
  end
21
25
 
22
26
  def find_or_create(args, &block)
@@ -6,10 +6,6 @@ module ActiveFolder
6
6
 
7
7
  class_methods do
8
8
  def current(path = nil)
9
- client = ActiveFolder.client
10
- connection = client.connection
11
-
12
- path ||= connection.current_path
13
9
  pathname = Pathname.new(path)
14
10
 
15
11
  dir = pathname.ascend do |file|
@@ -8,7 +8,7 @@ module ActiveFolder
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- def load!
11
+ def load
12
12
  attrs = attributes_file.load
13
13
  attrs.each_pair do |key,val|
14
14
  self[key] = val
@@ -17,23 +17,21 @@ module ActiveFolder
17
17
  self
18
18
  end
19
19
 
20
- def save!
20
+ def save
21
21
  attributes_file.save(attributes)
22
22
  self
23
23
  end
24
24
 
25
- def update!(**args)
26
- args.each { |k,v| self[k] = v }
27
- self.save!
28
- end
25
+ def save!; self.save end
29
26
 
30
27
  def update(**args)
31
28
  args.each { |k,v| self[k] = v }
32
29
  self.save
33
30
  end
34
31
 
35
- def load; self.load! end
36
- def save; self.save! end
32
+ def destroy
33
+ ActiveFolder.client.del(path: path)
34
+ end
37
35
 
38
36
  private
39
37
 
@@ -45,9 +43,10 @@ module ActiveFolder
45
43
 
46
44
  class_methods do
47
45
  def load(path)
48
- params = { name: File.basename(path), base_dir: File.dirname(path) }
49
- instance = self.new(**params)
50
- instance.load!; instance
46
+ instance = new(name: File.basename(path),
47
+ base_dir: File.dirname(path))
48
+
49
+ instance.load; instance
51
50
  end
52
51
  end
53
52
  end
@@ -8,7 +8,7 @@ require 'active_folder/model/traits/discovery'
8
8
  module ActiveFolder
9
9
  module Model
10
10
  module Traits
11
- module HasBelongs
11
+ module Relation
12
12
  using Utilities::Symbol
13
13
  extend ActiveSupport::Concern
14
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activefolder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Thorner
@@ -53,8 +53,8 @@ files:
53
53
  - lib/active_folder/model/traits/collection.rb
54
54
  - lib/active_folder/model/traits/discovery.rb
55
55
  - lib/active_folder/model/traits/enumeration.rb
56
- - lib/active_folder/model/traits/has_belongs.rb
57
56
  - lib/active_folder/model/traits/persistence.rb
57
+ - lib/active_folder/model/traits/relation.rb
58
58
  - lib/active_folder/model/utilities/collection.rb
59
59
  - lib/active_folder/model/utilities/match.rb
60
60
  - lib/active_folder/model/utilities/symbol.rb