activeyaml 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_yaml/factory_hash.rb +15 -0
- data/lib/active_yaml/{method_mapper.rb → method_redirection.rb} +8 -7
- data/lib/active_yaml/parser.rb +1 -1
- data/lib/active_yaml/version.rb +1 -1
- data/lib/active_yaml/{base_object.rb → yaml_hash.rb} +19 -13
- data/lib/active_yaml.rb +9 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b056e87f15b5ee397b8e5c317bdaf91703b264461931cac2e1faf274767161ff
|
4
|
+
data.tar.gz: 4b3841e988d29773aacbf01d5c9e721d8cae0ec6eb41225bc95307c02bed7bde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2827cb64f8e4f83452b2a8e4627ec2af41abd75121203ec053a611f3139422eb628c003b0441b56ddf6742fe072cea3f8fe1869ea5948ca794a88d59575107fa
|
7
|
+
data.tar.gz: ea713ef1ea725ba2756138fee5fee7e39769b80d3fa7276ad827f2b55080a9c67f500d6f8f3b61b0c3f9ff083cd266c43ec3f0d80e424b15bd603b838880716b
|
@@ -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
|
@@ -1,17 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'yaml_hash'
|
4
4
|
|
5
5
|
module ActiveYaml
|
6
|
-
#
|
7
|
-
|
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
|
8
9
|
def method_missing(method, *args, &block)
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
value = yaml_data[method.to_s]
|
11
|
+
|
12
|
+
if value
|
12
13
|
return value unless value.is_a?(Hash)
|
13
14
|
|
14
|
-
|
15
|
+
YamlHash.new(value)
|
15
16
|
else
|
16
17
|
super
|
17
18
|
end
|
data/lib/active_yaml/parser.rb
CHANGED
data/lib/active_yaml/version.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveYaml
|
4
|
-
#
|
5
|
-
class
|
6
|
-
attr_reader :hash
|
7
|
-
|
4
|
+
# Class for creating hashes of similar objects
|
5
|
+
class YamlHash
|
8
6
|
def initialize(hash)
|
9
|
-
@hash = hash
|
7
|
+
@hash = hash || {}
|
10
8
|
end
|
11
9
|
|
12
10
|
def method_missing(method, *args, &block)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
return
|
11
|
+
value = hash[method.to_s]
|
12
|
+
|
13
|
+
if value
|
14
|
+
return self.class.new(value) if value.is_a?(Hash)
|
17
15
|
|
18
16
|
value
|
19
17
|
else
|
@@ -21,12 +19,20 @@ module ActiveYaml
|
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
def respond_to_missing?(method, include_private = false)
|
25
|
-
@hash.key?(method.to_s) || super
|
26
|
-
end
|
27
|
-
|
28
22
|
def inspect
|
29
23
|
hash
|
30
24
|
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
hash.to_s
|
28
|
+
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
|
31
37
|
end
|
32
38
|
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/
|
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
|
-
|
8
|
-
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeyaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Leonov
|
@@ -31,10 +31,11 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/active_yaml.rb
|
34
|
-
- lib/active_yaml/
|
35
|
-
- lib/active_yaml/
|
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
|