activeyaml 0.1.5 → 1.0.1

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: df6ab1743032b2da062676da7582cfdf5728d3cfdde22005f967daf48a4b2e68
4
- data.tar.gz: dfae3e19537aaa71bb84ec9925a7b02eeff496c2d6a415198b9a26cfd16665c0
3
+ metadata.gz: b59e3eca883ff3ce07f8e5f6f5d1ddf3a2a10331987854a9c4137071573d684c
4
+ data.tar.gz: 80cc1a3fead0e93411a419633d5985eaaeda9eef88963695b05653ed105fee82
5
5
  SHA512:
6
- metadata.gz: 397f642b36da76e16faa2d3d033ae20394da142aa30d664ced8f1af54c9a168f1df83e7969295b9ab812e971406969f077ccd263b9f910801587f260dc7b3562
7
- data.tar.gz: 3baea001da73ce93fdc6c180d6a47e3ad3bf15357e2424a2503661548fd431960e692da2f21c8b31f0a979512fcf3c525432530c5caf5c114e931bd54890b418
6
+ metadata.gz: b5f0a3fa1e8dbb9d6446fdddd1da28c091287bf034db6b7bb507afe1f93fab4352279ed186895340272438ed83374e4339ac1f2e9ca8a78bcd6fbd8cea127524
7
+ data.tar.gz: 312629be17b050c0ddc705a927f58ea8ae56a0fa67b84ffb876284fcf59704e05d1fa895202e9c8f3bb51510d417de8fdc73be64d454479035bd1e014e83bb39
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'parser'
4
+ require_relative 'yaml_hash'
5
+
6
+ module ActiveYaml
7
+ # A module with methods that allows you,
8
+ # to work with Yaml files without creating models.
9
+ module FactoryHash
10
+ def create(file_path)
11
+ hash = Parser.parse(file_path)
12
+ YamlHash.new(hash)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'yaml_hash'
4
+
5
+ module ActiveYaml
6
+ # A module with methods for implementing tracking methods.
7
+ # In the model in order to proxy them into a hash with YML data
8
+ module MethodRedirection
9
+ def method_missing(method, *args, &)
10
+ value = yaml_data[method.to_s]
11
+
12
+ if value
13
+ return value unless value.is_a?(Hash)
14
+
15
+ YamlHash.new(value)
16
+ else
17
+ super
18
+ end
19
+ end
20
+
21
+ def respond_to_missing?(method, include_private = false)
22
+ yaml_data[method.to_s] || super
23
+ end
24
+ end
25
+ end
@@ -3,7 +3,7 @@
3
3
  require 'psych'
4
4
 
5
5
  module ActiveYaml
6
- # base parser
6
+ # The main parser of Yaml files, uses psych under the hood
7
7
  class Parser
8
8
  def self.parse(file_path)
9
9
  Psych.safe_load_file(file_path)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveYaml
4
- VERSION = '0.1.5'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveYaml
4
+ # Class for creating hashes of similar objects
5
+ class YamlHash
6
+ attr_reader :hash
7
+
8
+ def initialize(hash)
9
+ @hash = hash || {}
10
+ end
11
+
12
+ def method_missing(method, *args, &)
13
+ value = hash[method.to_s]
14
+
15
+ if value
16
+ return self.class.new(value) if value.is_a?(Hash)
17
+
18
+ value
19
+ else
20
+ super
21
+ end
22
+ end
23
+
24
+ def inspect
25
+ hash
26
+ end
27
+
28
+ def to_s
29
+ hash.to_s
30
+ end
31
+
32
+ def respond_to_missing?(method, include_private = false)
33
+ hash.key?(method.to_s) || super
34
+ end
35
+ end
36
+ end
data/lib/active_yaml.rb CHANGED
@@ -1,11 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'active_yaml/parser'
4
- require_relative 'active_yaml/method_mapper'
4
+ require_relative 'active_yaml/method_redirection'
5
+ require_relative 'active_yaml/factory_hash'
5
6
 
7
+ # The main module from which work with gem begins
6
8
  module ActiveYaml
7
- # base
8
- class Base < MethodMapper
9
+ extend FactoryHash
10
+
11
+ # Base class to inherit from to create models
12
+ class Base
13
+ include MethodRedirection
14
+
9
15
  def self.yaml(file_path)
10
16
  define_method(:yaml_data) do
11
17
  @yaml_data = Parser.parse(file_path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeyaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Leonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-01 00:00:00.000000000 Z
11
+ date: 2023-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
@@ -31,10 +31,11 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/active_yaml.rb
34
- - lib/active_yaml/base_object.rb
35
- - lib/active_yaml/method_mapper.rb
34
+ - lib/active_yaml/factory_hash.rb
35
+ - lib/active_yaml/method_redirection.rb
36
36
  - lib/active_yaml/parser.rb
37
37
  - lib/active_yaml/version.rb
38
+ - lib/active_yaml/yaml_hash.rb
38
39
  homepage: https://github.com/leonovk/activeyaml
39
40
  licenses:
40
41
  - MIT
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveYaml
4
- # base doc
5
- class BaseObject
6
- attr_reader :hash
7
-
8
- def initialize(hash)
9
- @hash = hash
10
- end
11
-
12
- def method_missing(method, *args, &block)
13
- method_name = method.to_s
14
- if hash.key?(method_name)
15
- value = hash[method_name]
16
- return BaseObject.new(value) if value.is_a?(Hash)
17
-
18
- value
19
- else
20
- super
21
- end
22
- end
23
-
24
- def respond_to_missing?(method, include_private = false)
25
- @hash.key?(method.to_s) || super
26
- end
27
-
28
- def inspect
29
- hash
30
- end
31
- end
32
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base_object'
4
-
5
- module ActiveYaml
6
- # base mapper
7
- class MethodMapper
8
- def method_missing(method, *args, &block)
9
- method_name = method.to_s
10
- if yaml_data[method_name]
11
- value = yaml_data[method_name]
12
- return value unless value.is_a?(Hash)
13
-
14
- BaseObject.new(value)
15
- else
16
- super
17
- end
18
- end
19
-
20
- def respond_to_missing?(method, include_private = false)
21
- yaml_data[method.to_s] || super
22
- end
23
- end
24
- end