activeyaml 1.1.1 → 1.2.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: f597f7a0892113b9d7c602f9cb76cc61da3d3a4b25650fa117088b58831202e5
4
- data.tar.gz: d2dc072ff789b4916c944b55886efa32caaf3d0c533d28d1738fdf57c374a368
3
+ metadata.gz: 1c14e874ae5a4bc7bdb26e0ad28b530481bee38a544943f0ac4caa9d0ea7c9c2
4
+ data.tar.gz: e3ed19ceb491d9560834fbc0666f7a5d71efa947411cf8143765b7b1a9877540
5
5
  SHA512:
6
- metadata.gz: fc6db90a8cfcd36a4861470b87d3d8f67c8753e7c5c1b2bdf931690838094ff07ebc476342e9409b74c5bf5bf669f08e0759e6ac9c672f6650fbff88587fc26c
7
- data.tar.gz: a6dba19bcef8563aa8677914d6a8a96aab6cc8b5f9df4b7749d08d78fa75e95cbe0df76f27bb8a9326e9f40430949f21a4cdd01336407b991fc3eec1bb30cdae
6
+ metadata.gz: e3ac4d370a59702c0b8482001d0cc77fa7619528a8f58650d09c8994624295a6f869925b9a8619e5f8cd49fab7fd922ad193d69877e755fcb6e2eb07df4f8e4e
7
+ data.tar.gz: 0e7214d66421768b5726f4913458ebaf5720956a167f5997bd78c71c246ddf2a1a617256f65fbdd8324c77d56e049f28fcc1e57dc0f459c162a80eb78a10b9a6
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'method_mapping'
4
+ require_relative 'parser'
5
+
6
+ module ActiveYaml
7
+ # A module that allows you to use this gem,
8
+ # without creating instances of the class
9
+ module ClassMethods
10
+ include MethodMapping
11
+
12
+ def yaml(file_path)
13
+ define_singleton_method(:yaml_data) do
14
+ @yaml_data = Parser.parse(file_path)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'yaml_hash'
4
+
5
+ module ActiveYaml
6
+ # A module containing methods that allow you to track method calls,
7
+ # and compare them with data from the YML file
8
+ module MethodMapping
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveYaml
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.1'
5
5
  end
data/lib/active_yaml.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'active_yaml/parser'
4
- require_relative 'active_yaml/yaml_hash'
4
+ require_relative 'active_yaml/method_mapping'
5
5
  require_relative 'active_yaml/factory_hash'
6
+ require_relative 'active_yaml/class_methods'
6
7
 
7
8
  # The main module from which work with gem begins
8
9
  module ActiveYaml
@@ -10,26 +11,12 @@ module ActiveYaml
10
11
 
11
12
  # Base class to inherit from to create models
12
13
  class BaseModel
14
+ include MethodMapping
15
+
13
16
  def self.yaml(file_path)
14
17
  define_method(:yaml_data) do
15
18
  @yaml_data = Parser.parse(file_path)
16
19
  end
17
20
  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
34
21
  end
35
22
  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: 1.1.1
4
+ version: 1.2.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-03 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
@@ -31,7 +31,9 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/active_yaml.rb
34
+ - lib/active_yaml/class_methods.rb
34
35
  - lib/active_yaml/factory_hash.rb
36
+ - lib/active_yaml/method_mapping.rb
35
37
  - lib/active_yaml/parser.rb
36
38
  - lib/active_yaml/version.rb
37
39
  - lib/active_yaml/yaml_hash.rb