yaml-ostruct 0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/yaml/ostruct.rb +24 -0
- data/lib/yaml/version.rb +4 -0
- data/lib/yaml/yaml_ostruct_impl.rb +50 -0
- metadata +6 -4
data/lib/yaml/ostruct.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'yaml/yaml_ostruct_impl'
|
2
|
+
|
3
|
+
# YamlOstruct module
|
4
|
+
module YamlOstruct
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def self.new
|
8
|
+
YamlOstructImpl.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.clear
|
12
|
+
@config = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.method_missing(method_sym, *args)
|
16
|
+
@config ||= YamlOstructImpl.new
|
17
|
+
@config.send method_sym, *args
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.load(dir)
|
21
|
+
@config ||= YamlOstructImpl.new
|
22
|
+
@config.load(dir)
|
23
|
+
end
|
24
|
+
end
|
data/lib/yaml/version.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'find'
|
2
|
+
require 'yaml'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'hashugar'
|
5
|
+
|
6
|
+
module YamlOstruct
|
7
|
+
# YamlOstructImpl class
|
8
|
+
class YamlOstructImpl
|
9
|
+
attr_reader :config
|
10
|
+
extend Gem::Deprecate
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@config = OpenStruct.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method_sym, *args)
|
17
|
+
if @config.respond_to? method_sym
|
18
|
+
@config.send method_sym, *args
|
19
|
+
elsif method_sym.to_s.end_with?('=')
|
20
|
+
@config.send method_sym, *args
|
21
|
+
elsif method_sym == :clear
|
22
|
+
@config = OpenStruct.new
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def load(dir)
|
29
|
+
fail "Parameter #{File.join(Dir.pwd, dir)} is not a valid directory" unless File.directory? dir
|
30
|
+
load_recursively(dir, @config)
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_recursively(dir, config)
|
34
|
+
files = Dir.entries(dir)
|
35
|
+
files.each do |file_name|
|
36
|
+
next if file_name.start_with?('.')
|
37
|
+
if File.directory?("#{dir}/#{file_name}")
|
38
|
+
new_config = OpenStruct.new
|
39
|
+
config.send("#{file_name}=", load_recursively("#{dir}/#{file_name}", new_config))
|
40
|
+
end
|
41
|
+
|
42
|
+
extension = File.extname(file_name)
|
43
|
+
next unless extension == '.yml' or extension == '.yaml'
|
44
|
+
new_config = YAML.load_file("#{dir}/#{file_name}")
|
45
|
+
config.send("#{File.basename(file_name, extension)}=", new_config.to_hashugar)
|
46
|
+
end
|
47
|
+
config
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml-ostruct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -33,7 +33,10 @@ email: hex0cter@gmail.com
|
|
33
33
|
executables: []
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
|
-
files:
|
36
|
+
files:
|
37
|
+
- lib/yaml/ostruct.rb
|
38
|
+
- lib/yaml/version.rb
|
39
|
+
- lib/yaml/yaml_ostruct_impl.rb
|
37
40
|
homepage: https://github.com/hex0cter/yaml-ostruct
|
38
41
|
licenses:
|
39
42
|
- MIT
|
@@ -58,6 +61,5 @@ rubyforge_project:
|
|
58
61
|
rubygems_version: 1.8.23.2
|
59
62
|
signing_key:
|
60
63
|
specification_version: 3
|
61
|
-
summary: Read yaml files
|
62
|
-
retaining the path
|
64
|
+
summary: Read yaml files with path into an OpenStruct
|
63
65
|
test_files: []
|