activefolder 1.0.0 → 1.1.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: d723e1b9eb722d530100fd75e13a97d744dd2e52
4
- data.tar.gz: 546326b52d4274cbe274f6584634ed0856b92d0c
3
+ metadata.gz: 672923824f8c9bb60475ac9af213cf362be4e30b
4
+ data.tar.gz: c55bf99d599342d2c2c7a6ae1a135967ac0ec853
5
5
  SHA512:
6
- metadata.gz: 24c74a9e783e9eae1507936258a53f6d8807d012c3a88d2a870aef9940a5d99c80b96498c878a790e891102875e6056bd37b27d3c5d9cf9f0d5f337dbb888008
7
- data.tar.gz: 439e64fc90e91311a24f5779130e0f0023e98a13b3d249b94b8c278d25a39d70efb2935878782ed46143d82014addaa3f7075b17fec0559681eaad1adceed516
6
+ metadata.gz: f55e4bdc4715481851750015292af632a6c60cb0dc5cb4cf3fe2c3774a6453b1c4662c90b700e250a3b03f8dfaad43e0b25edfbf14813534f21f0ef52084917a
7
+ data.tar.gz: 1befdaa45138de136cc29a03bb08eebbef408cc1a021fa09f601c35379c3e65eaa78f795ac02b2f6817047ae3b77c6cdbb24bc39f4e9b120d57ebd60e42e5a85
@@ -5,12 +5,12 @@ require 'active_folder/metal/errors'
5
5
  module ActiveFolder
6
6
  module Metal
7
7
  module Adapters
8
- class Bare
9
- def initialize(connection)
10
- @root = connection.root_path
8
+ class Local
9
+ def initialize(config)
10
+ @config = config
11
11
  end
12
12
 
13
- def read(path:)
13
+ def read(path)
14
14
  File.read full_path(path)
15
15
  rescue Errno::ENOENT => e
16
16
  raise NotFoundError.new(e)
@@ -18,35 +18,39 @@ module ActiveFolder
18
18
  raise SystemError.new(e)
19
19
  end
20
20
 
21
- def write(path:, data:)
22
- dir = File.dirname full_path(path)
23
- FileUtils.mkdir_p dir
21
+ def write(path, data)
24
22
  File.write(full_path(path), data)
25
23
  rescue SystemCallError => e
26
24
  raise SystemError.new(e)
27
25
  end
28
26
 
29
- def glob(path:)
30
- paths = Dir.glob full_path(path)
31
- paths.map { |p| relative_path(p) }
27
+ def mkdir_p(path)
28
+ FileUtils.mkdir_p full_path(path)
32
29
  rescue SystemCallError => e
33
30
  raise SystemError.new(e)
34
31
  end
35
32
 
36
- def del(path:)
33
+ def rm_r(path)
37
34
  FileUtils.rm_r full_path(path)
38
35
  rescue SystemCallError => e
39
36
  raise SystemError.new(e)
40
37
  end
41
38
 
39
+ def glob(path)
40
+ paths = Dir.glob full_path(path)
41
+ paths.map { |p| relative_path(p) }
42
+ rescue SystemCallError => e
43
+ raise SystemError.new(e)
44
+ end
45
+
42
46
  private
43
47
 
44
48
  def full_path(path)
45
- File.join(@root, path)
49
+ File.join(@config.root_path, path)
46
50
  end
47
51
 
48
52
  def relative_path(path)
49
- path.sub(@root, '')
53
+ path.sub(@config.root_path, '')
50
54
  end
51
55
  end
52
56
  end
@@ -1,46 +1,33 @@
1
- require 'active_folder/metal/adapters/bare'
2
- require 'active_folder/metal/connections/bare'
3
- require 'active_folder/metal/connections/git'
1
+ require 'active_folder/metal/adapters/local'
4
2
 
5
3
  module ActiveFolder
6
4
  module Metal
7
5
  class Client
8
6
  def initialize(config)
9
7
  @config = config
10
- @connection = connect(config)
11
8
  end
12
9
 
13
- def load(**args)
14
- adapter.read(**args)
10
+ def load(path:)
11
+ adapter.read(path)
15
12
  end
16
13
 
17
- def save(**args)
18
- adapter.write(**args)
14
+ def save(path:, data:)
15
+ adapter.mkdir_p File.dirname(path)
16
+ adapter.write(path, data)
19
17
  end
20
18
 
21
- def glob(**args)
22
- adapter.glob(**args)
19
+ def glob(path:)
20
+ adapter.glob(path)
23
21
  end
24
22
 
25
- def del(**args)
26
- adapter.del(**args)
27
- end
28
-
29
- def connection
30
- @connection
23
+ def del(path:)
24
+ adapter.rm_r(path)
31
25
  end
32
26
 
33
27
  private
34
28
 
35
- def connect(config)
36
- case config.root_path
37
- when :git then Connections::Git.new(config)
38
- else Connections::Bare.new(config)
39
- end
40
- end
41
-
42
29
  def adapter
43
- @adapter ||= Adapters::Bare.new(connection)
30
+ Adapters::Local.new(@config)
44
31
  end
45
32
  end
46
33
  end
@@ -1,11 +1,28 @@
1
+ require 'rugged'
2
+
3
+ require 'active_folder/metal/errors'
4
+
1
5
  module ActiveFolder
2
6
  module Metal
3
7
  class Config
4
- attr_accessor :root_path
8
+ attr_writer :root_path
5
9
 
6
10
  def initialize
7
11
  self.root_path = '.'
8
12
  end
13
+
14
+ def root_path
15
+ @root_path != :git ? @root_path :
16
+ rugged.discover(Dir.pwd)
17
+ rescue Rugged::RepositoryError => e
18
+ raise SystemError.new(e)
19
+ end
20
+
21
+ private
22
+
23
+ def rugged
24
+ Rugged::Repository
25
+ end
9
26
  end
10
27
  end
11
28
  end
@@ -5,7 +5,7 @@ module ActiveFolder
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  class_methods do
8
- def current(path = nil)
8
+ def find_by_path(path)
9
9
  pathname = Pathname.new(path)
10
10
 
11
11
  dir = pathname.ascend do |file|
@@ -12,32 +12,22 @@ module ActiveFolder
12
12
  end
13
13
 
14
14
  def all(name = '*')
15
- element = File.join(model_name, name)
16
- query = File.join(model_base_dir, '**', element)
15
+ query_suffix = File.join(model_name, name)
16
+ query = File.join(model_base_dir, '**', query_suffix)
17
17
 
18
18
  paths = ActiveFolder.client.glob(path: query)
19
19
  paths.map { |path| model_class.load(path) }
20
20
  end
21
21
 
22
- def last
23
- all.last
24
- end
25
-
26
- def first
27
- all.first
28
- end
22
+ def last; all.last end
23
+ def first; all.first end
29
24
 
30
- def to_a
31
- all
32
- end
25
+ def count; all.count end
26
+ def to_a; all end
33
27
 
34
28
  def where(**args)
35
29
  all.select { |element| args.match(element) }
36
30
  end
37
-
38
- def count
39
- all.count
40
- end
41
31
  end
42
32
  end
43
33
  end
@@ -11,7 +11,6 @@ module ActiveFolder
11
11
  module Relation
12
12
  using Utilities::Symbol
13
13
  extend ActiveSupport::Concern
14
-
15
14
  include Discovery
16
15
 
17
16
  class_methods do
@@ -23,7 +22,7 @@ module ActiveFolder
23
22
 
24
23
  def belongs_to element
25
24
  define_method element do
26
- element.to_class.current(self.path)
25
+ element.to_class.find_by_path(self.path)
27
26
  end
28
27
  end
29
28
 
@@ -8,12 +8,12 @@ module ActiveFolder
8
8
  using Utilities::Symbol
9
9
  include Model::Traits::Collection
10
10
 
11
- def initialize(owner, collection)
12
- @owner = owner; @collection = collection
11
+ def initialize(owner, name)
12
+ @owner = owner; @name = name
13
13
  end
14
14
 
15
- def model_class; @collection.to_class end
16
- def model_name; @collection.to_s end
15
+ def model_class; @name.to_class end
16
+ def model_name; @name.to_s end
17
17
  def model_base_dir; @owner.path end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activefolder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Thorner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-30 00:00:00.000000000 Z
11
+ date: 2016-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -41,11 +41,9 @@ files:
41
41
  - lib/active_folder/base.rb
42
42
  - lib/active_folder/config.rb
43
43
  - lib/active_folder/errors.rb
44
- - lib/active_folder/metal/adapters/bare.rb
44
+ - lib/active_folder/metal/adapters/local.rb
45
45
  - lib/active_folder/metal/client.rb
46
46
  - lib/active_folder/metal/config.rb
47
- - lib/active_folder/metal/connections/bare.rb
48
- - lib/active_folder/metal/connections/git.rb
49
47
  - lib/active_folder/metal/errors.rb
50
48
  - lib/active_folder/metal/files/text.rb
51
49
  - lib/active_folder/metal/files/yaml.rb
@@ -1,15 +0,0 @@
1
- module ActiveFolder
2
- module Metal
3
- module Connections
4
- class Bare
5
- def initialize(config)
6
- @config = config
7
- end
8
-
9
- def root_path
10
- @config.root_path
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,23 +0,0 @@
1
- require 'rugged'
2
-
3
- module ActiveFolder
4
- module Metal
5
- module Connections
6
- class Git
7
- def initialize(config)
8
- @config = config
9
- end
10
-
11
- def root_path
12
- rugged.discover(Dir.pwd)
13
- rescue Rugged::RepositoryError => e
14
- raise SystemError.new(e)
15
- end
16
-
17
- private
18
-
19
- def rugged; Rugged::Repository end
20
- end
21
- end
22
- end
23
- end