activefolder 0.0.3 → 0.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: 5bdc8dd156be2cd626fb59f795a5f3efa00cd1ef
4
- data.tar.gz: e51dcb7fe4f44018afcbf50cbba24b4de13fb3cb
3
+ metadata.gz: 0c797caee9bc346c2117c06b66e00541b7526c7a
4
+ data.tar.gz: 54c7374922603db20c35ac5e6212f5c55d446e60
5
5
  SHA512:
6
- metadata.gz: 06daf6a7afcd64c93e615d0912844dab4ff69cc595256918c22fc1e630b02516fa5358357a1af20e3bfd95cbccb21b54ab3d1aab53ee52901b40b56e92a4fdd1
7
- data.tar.gz: 863793c1a6386a456042ace4063aa19e4f18b588fa9479be8ac7715e0fff90aeffe77c7b5b9ca0473e0e6e41471e5b3707fd244f73312a3e51a39f48112b8324
6
+ metadata.gz: ead8a1ac4b1b0c938e06432841dcdaf40db5112ccda118f1ee22009ff865a55b5ae45ba9eab2b69000d9fc11a415029114e4d1ca6771a93bb3a91e83d64d8bb1
7
+ data.tar.gz: 999b3312d5c2484c00c833e7ca14fedd6c332e05cf08f5bff6784fcd5cd31d1cae9187bfcbcf4e3350292346f2d2ffb80283e51459ab5f5de0b5824d95b09058
@@ -12,6 +12,8 @@ module ActiveFolder
12
12
 
13
13
  def read(path:)
14
14
  File.read full_path(path)
15
+ rescue Errno::ENOENT => e
16
+ raise NotFoundError.new(e)
15
17
  rescue SystemCallError => e
16
18
  raise SystemError.new(e)
17
19
  end
@@ -4,5 +4,6 @@ module ActiveFolder
4
4
  module Metal
5
5
  class SyntaxError < Error; end
6
6
  class SystemError < Error; end
7
+ class NotFoundError < Error; end
7
8
  end
8
9
  end
@@ -0,0 +1,29 @@
1
+ module ActiveFolder
2
+ module Metal
3
+ module Files
4
+ class Text
5
+ def initialize(dir:, name:)
6
+ @dir = dir; @name = name
7
+ end
8
+
9
+ def load
10
+ client.load(path: path)
11
+ end
12
+
13
+ def save(content)
14
+ client.save(path: path, data: content.to_s)
15
+ end
16
+
17
+ private
18
+
19
+ def client
20
+ ActiveFolder.client
21
+ end
22
+
23
+ def path
24
+ File.join(@dir, @name)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,10 +1,10 @@
1
- require 'active_folder/model/utilities/matcher'
1
+ require 'active_folder/model/utilities/match'
2
2
 
3
3
  module ActiveFolder
4
4
  module Model
5
5
  module Traits
6
6
  module Enumeration
7
- using Utilities::Matcher
7
+ using Utilities::Match
8
8
 
9
9
  def find(name)
10
10
  results = all(name)
@@ -1,24 +1,45 @@
1
1
  require 'pathname'
2
2
 
3
3
  require 'active_folder/model/utilities/collection'
4
+ require 'active_folder/model/utilities/symbol'
5
+ require 'active_folder/metal/files/text'
4
6
 
5
7
  module ActiveFolder
6
8
  module Model
7
9
  module Traits
8
10
  module HasBelongs
11
+ using Utilities::Symbol
9
12
  extend ActiveSupport::Concern
10
13
 
11
14
  class_methods do
12
15
  def has_many collection
13
16
  define_method collection do
14
- Utilities::Collection.new(self, collection.to_s)
17
+ Utilities::Collection.new(self, collection)
15
18
  end
16
19
  end
17
20
 
18
21
  def belongs_to element
19
22
  define_method element do
20
- model_class = element.to_s.classify.constantize
21
- model_class.current(self.path)
23
+ element.to_class.current(self.path)
24
+ end
25
+ end
26
+
27
+ def has_one element
28
+ define_method :link_file do |name|
29
+ params = { dir: path, name: name.to_s }
30
+ Metal::Files::Text.new(**params)
31
+ end
32
+
33
+ define_method element do
34
+ begin
35
+ path = link_file(element).load
36
+ element.to_class.load(path)
37
+ rescue Metal::NotFoundError => _
38
+ end
39
+ end
40
+
41
+ define_method "#{element}=" do |value|
42
+ link_file(element).save(value.path)
22
43
  end
23
44
  end
24
45
 
@@ -1,20 +1,19 @@
1
1
  require 'active_folder/model/traits/collection'
2
+ require 'active_folder/model/utilities/symbol'
2
3
 
3
4
  module ActiveFolder
4
5
  module Model
5
6
  module Utilities
6
7
  class Collection
8
+ using Utilities::Symbol
7
9
  include Model::Traits::Collection
8
10
 
9
11
  def initialize(owner, collection)
10
12
  @owner = owner; @collection = collection
11
13
  end
12
14
 
13
- def model_class
14
- @collection.classify.constantize
15
- end
16
-
17
- def model_name; @collection end
15
+ def model_class; @collection.to_class end
16
+ def model_name; @collection.to_s end
18
17
  def model_base_dir; @owner.path end
19
18
  end
20
19
  end
@@ -3,7 +3,7 @@ require 'active_folder/model/traits/enumeration'
3
3
  module ActiveFolder
4
4
  module Model
5
5
  module Utilities
6
- module Matcher
6
+ module Match
7
7
  refine Object do
8
8
  def match(object); self == object end
9
9
  end
@@ -0,0 +1,13 @@
1
+ module ActiveFolder
2
+ module Model
3
+ module Utilities
4
+ module Symbol
5
+ refine ::Symbol do
6
+ def to_class
7
+ to_s.classify.constantize
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ 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: 0.0.3
4
+ version: 0.0.4
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-29 00:00:00.000000000 Z
11
+ date: 2015-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -45,6 +45,7 @@ files:
45
45
  - lib/active_folder/metal/config.rb
46
46
  - lib/active_folder/metal/connections/bare.rb
47
47
  - lib/active_folder/metal/errors.rb
48
+ - lib/active_folder/metal/files/text.rb
48
49
  - lib/active_folder/metal/files/yaml.rb
49
50
  - lib/active_folder/model/errors.rb
50
51
  - lib/active_folder/model/traits/collection.rb
@@ -52,7 +53,8 @@ files:
52
53
  - lib/active_folder/model/traits/has_belongs.rb
53
54
  - lib/active_folder/model/traits/persistence.rb
54
55
  - lib/active_folder/model/utilities/collection.rb
55
- - lib/active_folder/model/utilities/matcher.rb
56
+ - lib/active_folder/model/utilities/match.rb
57
+ - lib/active_folder/model/utilities/symbol.rb
56
58
  homepage: https://github.com/benthorner/active_folder
57
59
  licenses:
58
60
  - GNU GPL v2.0