activeyaml 1.0.1 → 1.2.0

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: b59e3eca883ff3ce07f8e5f6f5d1ddf3a2a10331987854a9c4137071573d684c
4
- data.tar.gz: 80cc1a3fead0e93411a419633d5985eaaeda9eef88963695b05653ed105fee82
3
+ metadata.gz: 2d6f31a30be9442d2006d3a021c8c67e094cd85fe4836b64772126011e3c30dd
4
+ data.tar.gz: 36e100c38e94324625d7497660710b008fd02425d23b482b027ebe544920766f
5
5
  SHA512:
6
- metadata.gz: b5f0a3fa1e8dbb9d6446fdddd1da28c091287bf034db6b7bb507afe1f93fab4352279ed186895340272438ed83374e4339ac1f2e9ca8a78bcd6fbd8cea127524
7
- data.tar.gz: 312629be17b050c0ddc705a927f58ea8ae56a0fa67b84ffb876284fcf59704e05d1fa895202e9c8f3bb51510d417de8fdc73be64d454479035bd1e014e83bb39
6
+ metadata.gz: ec1821333bd0ea118fa3bd0c9e46316557513272c9f012b5ba878b91f8bcf27801eb31ec4dd731b8465e2280dff5856387c08d3df0af7974a1dd4b6fe94dee20
7
+ data.tar.gz: 70b1d65e75e4f7ae1c3246e7dedd3ff098e5ba59daac803686d725448b2ad3d4c850934c0bd85838b524ca7f0fa60d29b570c8e714761df8625784749fcf25a0
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'method_mapper'
4
+ require_relative 'parser'
5
+
6
+ module ActiveYaml
7
+ # no doc
8
+ module ClassMethods
9
+ include MethodMapper
10
+
11
+ def yaml(file_path)
12
+ define_singleton_method(:yaml_data) do
13
+ @yaml_data = Parser.parse(file_path)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,9 +3,8 @@
3
3
  require_relative 'yaml_hash'
4
4
 
5
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
6
+ # no doc
7
+ module MethodMapper
9
8
  def method_missing(method, *args, &)
10
9
  value = yaml_data[method.to_s]
11
10
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveYaml
4
- VERSION = '1.0.1'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -9,6 +9,8 @@ module ActiveYaml
9
9
  @hash = hash || {}
10
10
  end
11
11
 
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
12
14
  def method_missing(method, *args, &)
13
15
  value = hash[method.to_s]
14
16
 
@@ -21,6 +23,10 @@ module ActiveYaml
21
23
  end
22
24
  end
23
25
 
26
+ def respond_to_missing?(method, include_private = false)
27
+ hash.key?(method.to_s) || super
28
+ end
29
+
24
30
  def inspect
25
31
  hash
26
32
  end
@@ -28,9 +34,5 @@ module ActiveYaml
28
34
  def to_s
29
35
  hash.to_s
30
36
  end
31
-
32
- def respond_to_missing?(method, include_private = false)
33
- hash.key?(method.to_s) || super
34
- end
35
37
  end
36
38
  end
data/lib/active_yaml.rb CHANGED
@@ -1,16 +1,17 @@
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/method_mapper'
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
9
10
  extend FactoryHash
10
11
 
11
12
  # Base class to inherit from to create models
12
- class Base
13
- include MethodRedirection
13
+ class BaseModel
14
+ include MethodMapper
14
15
 
15
16
  def self.yaml(file_path)
16
17
  define_method(:yaml_data) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeyaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Leonov
@@ -31,8 +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
35
- - lib/active_yaml/method_redirection.rb
36
+ - lib/active_yaml/method_mapper.rb
36
37
  - lib/active_yaml/parser.rb
37
38
  - lib/active_yaml/version.rb
38
39
  - lib/active_yaml/yaml_hash.rb