-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
69 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'active_yaml/parser' | ||
require_relative 'active_yaml/method_redirection' | ||
require_relative 'active_yaml/yaml_hash' | ||
require_relative 'active_yaml/factory_hash' | ||
|
||
# The main module from which work with gem begins | ||
module ActiveYaml | ||
extend FactoryHash | ||
|
||
# Base class to inherit from to create models | ||
class Base | ||
include MethodRedirection | ||
|
||
class BaseModel | ||
def self.yaml(file_path) | ||
define_method(:yaml_data) do | ||
@yaml_data = Parser.parse(file_path) | ||
end | ||
end | ||
|
||
def method_missing(method, *args, &) | ||
value = yaml_data[method.to_s] | ||
|
||
if value | ||
return value unless value.is_a?(Hash) | ||
|
||
YamlHash.new(value) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def respond_to_missing?(method, include_private = false) | ||
yaml_data[method.to_s] || super | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveYaml | ||
VERSION = '1.0.1' | ||
VERSION = '1.1.1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../test_helper' | ||
|
||
module ActiveYaml | ||
class ParserTest < Minitest::Test | ||
def test_parse | ||
expect_hash = { 'yaml' => { 'kek' => { 'lol' => 'text', 'cheburek' => 'cheburek', | ||
'users' => { 'first' => '1' } } } } | ||
result = Parser.parse('.examples/example.yaml') | ||
|
||
assert_equal result, expect_hash | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../test_helper' | ||
|
||
module ActiveYaml | ||
class VersionTest < Minitest::Test | ||
def test_version | ||
refute_nil VERSION | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters