activeyaml 0.1.6 → 1.1.1

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
  SHA256:
3
- metadata.gz: b056e87f15b5ee397b8e5c317bdaf91703b264461931cac2e1faf274767161ff
4
- data.tar.gz: 4b3841e988d29773aacbf01d5c9e721d8cae0ec6eb41225bc95307c02bed7bde
3
+ metadata.gz: f597f7a0892113b9d7c602f9cb76cc61da3d3a4b25650fa117088b58831202e5
4
+ data.tar.gz: d2dc072ff789b4916c944b55886efa32caaf3d0c533d28d1738fdf57c374a368
5
5
  SHA512:
6
- metadata.gz: 2827cb64f8e4f83452b2a8e4627ec2af41abd75121203ec053a611f3139422eb628c003b0441b56ddf6742fe072cea3f8fe1869ea5948ca794a88d59575107fa
7
- data.tar.gz: ea713ef1ea725ba2756138fee5fee7e39769b80d3fa7276ad827f2b55080a9c67f500d6f8f3b61b0c3f9ff083cd266c43ec3f0d80e424b15bd603b838880716b
6
+ metadata.gz: fc6db90a8cfcd36a4861470b87d3d8f67c8753e7c5c1b2bdf931690838094ff07ebc476342e9409b74c5bf5bf669f08e0759e6ac9c672f6650fbff88587fc26c
7
+ data.tar.gz: a6dba19bcef8563aa8677914d6a8a96aab6cc8b5f9df4b7749d08d78fa75e95cbe0df76f27bb8a9326e9f40430949f21a4cdd01336407b991fc3eec1bb30cdae
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveYaml
4
- VERSION = '0.1.6'
4
+ VERSION = '1.1.1'
5
5
  end
@@ -3,11 +3,15 @@
3
3
  module ActiveYaml
4
4
  # Class for creating hashes of similar objects
5
5
  class YamlHash
6
+ attr_reader :hash
7
+
6
8
  def initialize(hash)
7
9
  @hash = hash || {}
8
10
  end
9
11
 
10
- def method_missing(method, *args, &block)
12
+ # The main logic of this class is implemented in this method.
13
+ # Allows you to filter method calls and redirect them to a hash by key
14
+ def method_missing(method, *args, &)
11
15
  value = hash[method.to_s]
12
16
 
13
17
  if value
@@ -19,6 +23,10 @@ module ActiveYaml
19
23
  end
20
24
  end
21
25
 
26
+ def respond_to_missing?(method, include_private = false)
27
+ hash.key?(method.to_s) || super
28
+ end
29
+
22
30
  def inspect
23
31
  hash
24
32
  end
@@ -26,13 +34,5 @@ module ActiveYaml
26
34
  def to_s
27
35
  hash.to_s
28
36
  end
29
-
30
- def respond_to_missing?(method, include_private = false)
31
- hash.key?(method.to_s) || super
32
- end
33
-
34
- private
35
-
36
- attr_reader :hash
37
37
  end
38
38
  end
data/lib/active_yaml.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'active_yaml/parser'
4
- require_relative 'active_yaml/method_redirection'
4
+ require_relative 'active_yaml/yaml_hash'
5
5
  require_relative 'active_yaml/factory_hash'
6
6
 
7
7
  # The main module from which work with gem begins
@@ -9,13 +9,27 @@ module ActiveYaml
9
9
  extend FactoryHash
10
10
 
11
11
  # Base class to inherit from to create models
12
- class Base
13
- include MethodRedirection
14
-
12
+ class BaseModel
15
13
  def self.yaml(file_path)
16
14
  define_method(:yaml_data) do
17
15
  @yaml_data = Parser.parse(file_path)
18
16
  end
19
17
  end
18
+
19
+ def method_missing(method, *args, &)
20
+ value = yaml_data[method.to_s]
21
+
22
+ if value
23
+ return value unless value.is_a?(Hash)
24
+
25
+ YamlHash.new(value)
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ def respond_to_missing?(method, include_private = false)
32
+ yaml_data[method.to_s] || super
33
+ end
20
34
  end
21
35
  end
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.6
4
+ version: 1.1.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
@@ -32,7 +32,6 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - lib/active_yaml.rb
34
34
  - lib/active_yaml/factory_hash.rb
35
- - lib/active_yaml/method_redirection.rb
36
35
  - lib/active_yaml/parser.rb
37
36
  - lib/active_yaml/version.rb
38
37
  - lib/active_yaml/yaml_hash.rb
@@ -1,25 +0,0 @@
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, &block)
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