activefolder 0.0.4 → 0.0.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.
- checksums.yaml +4 -4
- data/lib/active_folder/metal/client.rb +13 -4
- data/lib/active_folder/metal/connections/bare.rb +4 -0
- data/lib/active_folder/metal/connections/git.rb +25 -0
- data/lib/active_folder/model/traits/collection.rb +14 -6
- data/lib/active_folder/model/traits/discovery.rb +26 -0
- data/lib/active_folder/model/traits/enumeration.rb +4 -0
- data/lib/active_folder/model/traits/has_belongs.rb +3 -11
- data/lib/active_folder/model/traits/persistence.rb +6 -2
- data/lib/active_folder/model/utilities/match.rb +4 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020e30e40612918e0063d5fa36fb3aff3c293eed
|
4
|
+
data.tar.gz: 8e382664812b53c6ec4d315d9d43096e4a62bbb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a8ef1fc3d7553f8c3f6164faa1049e880efa319271ba21e6a49b3aa74e580354debd83e0c539fb950af8adb61be85e200eb8c3b3577fc8d8e8d616f8d346e4
|
7
|
+
data.tar.gz: 552e0b30ee18334dbd48092dbbaacb074661e7f546235ebf2c141d6d259dc3b668d24ad3d75d77ce9a7582d733f4f2e712cf4657815caae7383761cdb066fb26
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'active_folder/metal/adapters/bare'
|
2
2
|
require 'active_folder/metal/connections/bare'
|
3
|
+
require 'active_folder/metal/connections/git'
|
3
4
|
|
4
5
|
module ActiveFolder
|
5
6
|
module Metal
|
6
7
|
class Client
|
7
8
|
def initialize(config)
|
8
9
|
@config = config
|
10
|
+
@connection = connect(config)
|
9
11
|
end
|
10
12
|
|
11
13
|
def load(**args)
|
@@ -20,14 +22,21 @@ module ActiveFolder
|
|
20
22
|
adapter.glob(**args)
|
21
23
|
end
|
22
24
|
|
25
|
+
def connection
|
26
|
+
@connection
|
27
|
+
end
|
28
|
+
|
23
29
|
private
|
24
30
|
|
25
|
-
def
|
26
|
-
|
31
|
+
def connect(config)
|
32
|
+
case config.root_path
|
33
|
+
when :git then Connections::Git.new(config)
|
34
|
+
else Connections::Bare.new(config)
|
35
|
+
end
|
27
36
|
end
|
28
37
|
|
29
|
-
def
|
30
|
-
@
|
38
|
+
def adapter
|
39
|
+
@adapter ||= Adapters::Bare.new(connection)
|
31
40
|
end
|
32
41
|
end
|
33
42
|
end
|
@@ -0,0 +1,25 @@
|
|
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 current_path; Dir.pwd end
|
12
|
+
|
13
|
+
def root_path
|
14
|
+
rugged.discover(current_path)
|
15
|
+
rescue Rugged::RepositoryError => e
|
16
|
+
raise SystemError.new(e)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def rugged; Rugged::Repository end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -6,17 +6,25 @@ module ActiveFolder
|
|
6
6
|
module Collection
|
7
7
|
include Enumeration
|
8
8
|
|
9
|
-
def build(
|
9
|
+
def build(args, &block)
|
10
10
|
dir = File.join(model_base_dir, model_name)
|
11
|
-
|
11
|
+
args = args.merge(base_dir: dir)
|
12
|
+
|
13
|
+
instance = model_class.new(args)
|
14
|
+
yield instance if block_given?; instance
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(args, &block)
|
18
|
+
instance = build(args, &block);
|
19
|
+
instance.save!; instance
|
12
20
|
end
|
13
21
|
|
14
|
-
def
|
15
|
-
|
22
|
+
def find_or_create(args, &block)
|
23
|
+
find(args[:name]) || create(args, &block)
|
16
24
|
end
|
17
25
|
|
18
|
-
def
|
19
|
-
find(args[:name]) ||
|
26
|
+
def find_or_initialize(args, &block)
|
27
|
+
find(args[:name]) || build(args, &block)
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveFolder
|
2
|
+
module Model
|
3
|
+
module Traits
|
4
|
+
module Discovery
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def current(path = nil)
|
9
|
+
client = ActiveFolder.client
|
10
|
+
connection = client.connection
|
11
|
+
|
12
|
+
path ||= connection.current_path
|
13
|
+
pathname = Pathname.new(path)
|
14
|
+
|
15
|
+
dir = pathname.ascend do |file|
|
16
|
+
parent_dir = file.parent.basename.to_s
|
17
|
+
break(file) if parent_dir == model_name
|
18
|
+
end
|
19
|
+
|
20
|
+
model_class.load(dir) if dir
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -3,6 +3,7 @@ require 'pathname'
|
|
3
3
|
require 'active_folder/model/utilities/collection'
|
4
4
|
require 'active_folder/model/utilities/symbol'
|
5
5
|
require 'active_folder/metal/files/text'
|
6
|
+
require 'active_folder/model/traits/discovery'
|
6
7
|
|
7
8
|
module ActiveFolder
|
8
9
|
module Model
|
@@ -11,6 +12,8 @@ module ActiveFolder
|
|
11
12
|
using Utilities::Symbol
|
12
13
|
extend ActiveSupport::Concern
|
13
14
|
|
15
|
+
include Discovery
|
16
|
+
|
14
17
|
class_methods do
|
15
18
|
def has_many collection
|
16
19
|
define_method collection do
|
@@ -42,17 +45,6 @@ module ActiveFolder
|
|
42
45
|
link_file(element).save(value.path)
|
43
46
|
end
|
44
47
|
end
|
45
|
-
|
46
|
-
def current(path = Dir.pwd)
|
47
|
-
pathname = Pathname.new(path)
|
48
|
-
|
49
|
-
dir = pathname.ascend do |file|
|
50
|
-
parent_dir = file.parent.basename.to_s
|
51
|
-
break(file) if parent_dir == model_name
|
52
|
-
end
|
53
|
-
|
54
|
-
model_class.load(dir) if dir
|
55
|
-
end
|
56
48
|
end
|
57
49
|
end
|
58
50
|
end
|
@@ -10,12 +10,16 @@ module ActiveFolder
|
|
10
10
|
included do
|
11
11
|
def load!
|
12
12
|
attrs = attributes_file.load
|
13
|
-
|
14
|
-
|
13
|
+
attrs.each_pair do |key,val|
|
14
|
+
self[key] = val
|
15
|
+
end
|
16
|
+
|
17
|
+
self
|
15
18
|
end
|
16
19
|
|
17
20
|
def save!
|
18
21
|
attributes_file.save(attributes)
|
22
|
+
self
|
19
23
|
end
|
20
24
|
|
21
25
|
def update!(**args)
|
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.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Thorner
|
@@ -30,7 +30,8 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 4.2.5
|
33
|
-
description: A file system ORM
|
33
|
+
description: A file system ORM based on ActiveRecord. Objects are files, relations
|
34
|
+
are folders.
|
34
35
|
email: benthorner@outlook.com
|
35
36
|
executables: []
|
36
37
|
extensions: []
|
@@ -44,11 +45,13 @@ files:
|
|
44
45
|
- lib/active_folder/metal/client.rb
|
45
46
|
- lib/active_folder/metal/config.rb
|
46
47
|
- lib/active_folder/metal/connections/bare.rb
|
48
|
+
- lib/active_folder/metal/connections/git.rb
|
47
49
|
- lib/active_folder/metal/errors.rb
|
48
50
|
- lib/active_folder/metal/files/text.rb
|
49
51
|
- lib/active_folder/metal/files/yaml.rb
|
50
52
|
- lib/active_folder/model/errors.rb
|
51
53
|
- lib/active_folder/model/traits/collection.rb
|
54
|
+
- lib/active_folder/model/traits/discovery.rb
|
52
55
|
- lib/active_folder/model/traits/enumeration.rb
|
53
56
|
- lib/active_folder/model/traits/has_belongs.rb
|
54
57
|
- lib/active_folder/model/traits/persistence.rb
|
@@ -78,5 +81,5 @@ rubyforge_project:
|
|
78
81
|
rubygems_version: 2.4.5
|
79
82
|
signing_key:
|
80
83
|
specification_version: 4
|
81
|
-
summary:
|
84
|
+
summary: A file system ORM based on ActiveRecord.
|
82
85
|
test_files: []
|