nugrant 2.1.2 → 2.1.4
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.
- checksums.yaml +5 -5
- data/.gitignore +23 -23
- data/.travis.yml +15 -10
- data/CHANGELOG.md +347 -338
- data/CONTRIBUTORS.md +7 -5
- data/Gemfile +13 -13
- data/README.md +601 -601
- data/lib/nugrant/bag.rb +264 -264
- data/lib/nugrant/config.rb +201 -201
- data/lib/nugrant/helper/bag.rb +38 -38
- data/lib/nugrant/helper/env/exporter.rb +195 -195
- data/lib/nugrant/helper/env/namer.rb +47 -47
- data/lib/nugrant/helper/parameters.rb +12 -12
- data/lib/nugrant/helper/stack.rb +86 -86
- data/lib/nugrant/mixin/parameters.rb +178 -178
- data/lib/nugrant/parameters.rb +29 -29
- data/lib/nugrant/vagrant/errors.rb +35 -35
- data/lib/nugrant/vagrant/v2/action/auto_export.rb +45 -45
- data/lib/nugrant/vagrant/v2/action.rb +17 -17
- data/lib/nugrant/vagrant/v2/command/env.rb +118 -118
- data/lib/nugrant/vagrant/v2/command/parameters.rb +153 -153
- data/lib/nugrant/vagrant/v2/command/restricted_keys.rb +64 -64
- data/lib/nugrant/vagrant/v2/command/root.rb +95 -95
- data/lib/nugrant/vagrant/v2/config/user.rb +29 -29
- data/lib/nugrant/vagrant/v2/helper.rb +96 -96
- data/lib/nugrant/vagrant/v2/plugin.rb +34 -34
- data/lib/nugrant/version.rb +3 -3
- data/lib/nugrant.rb +31 -31
- data/locales/en.yml +24 -24
- data/locales/fr.yml +24 -24
- data/nugrant.gemspec +32 -32
- data/test/lib/nugrant/helper/env/test_exporter.rb +238 -238
- data/test/lib/nugrant/helper/test_bag.rb +16 -16
- data/test/lib/nugrant/helper/test_parameters.rb +17 -17
- data/test/lib/nugrant/helper/test_stack.rb +152 -152
- data/test/lib/nugrant/test_bag.rb +450 -450
- data/test/lib/nugrant/test_config.rb +201 -201
- data/test/lib/nugrant/test_parameters.rb +438 -438
- data/test/lib/test_helper.rb +3 -3
- data/test/resources/README.md +52 -52
- data/test/resources/json/params_current_1.json +6 -6
- data/test/resources/json/params_current_2.json +29 -29
- data/test/resources/json/params_user_nil_values.json +9 -9
- data/test/resources/vagrantfiles/v2.auto_export +13 -13
- data/test/resources/vagrantfiles/v2.bag_inside_array +15 -15
- data/test/resources/vagrantfiles/v2.defaults_mixed_string_symbols +18 -18
- data/test/resources/vagrantfiles/v2.defaults_null_values_in_vagrantuser +23 -23
- data/test/resources/vagrantfiles/v2.defaults_using_string +18 -18
- data/test/resources/vagrantfiles/v2.defaults_using_symbol +18 -18
- data/test/resources/vagrantfiles/v2.empty +2 -2
- data/test/resources/vagrantfiles/v2.fake +29 -29
- data/test/resources/vagrantfiles/v2.missing_parameter +3 -3
- data/test/resources/vagrantfiles/v2.real +22 -22
- data/test/resources/yaml/params_array.yml +5 -5
- data/test/resources/yaml/params_boolean.yml +1 -1
- data/test/resources/yaml/params_combinations.yml +72 -72
- data/test/resources/yaml/params_current_1.yml +4 -4
- data/test/resources/yaml/params_current_2.yml +23 -23
- data/test/resources/yaml/params_defaults_at_root.yml +1 -1
- data/test/resources/yaml/params_defaults_not_at_root.yml +2 -2
- data/test/resources/yaml/params_list.yml +2 -2
- data/test/resources/yaml/params_numeric_key.yml +3 -3
- data/test/resources/yaml/params_simple.yml +1 -1
- data/test/resources/yaml/params_system_1.yml +4 -4
- data/test/resources/yaml/params_system_2.yml +25 -25
- data/test/resources/yaml/params_unix_eol.yml +3 -3
- data/test/resources/yaml/params_user_1.yml +4 -4
- data/test/resources/yaml/params_user_2.yml +23 -23
- data/test/resources/yaml/params_user_nil_values.yml +5 -5
- data/test/resources/yaml/params_windows_eol.yml +3 -3
- metadata +12 -13
data/lib/nugrant/config.rb
CHANGED
@@ -1,201 +1,201 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
|
-
module Nugrant
|
4
|
-
class Config
|
5
|
-
DEFAULT_ARRAY_MERGE_STRATEGY = :replace
|
6
|
-
DEFAULT_PARAMS_FILENAME = ".nuparams"
|
7
|
-
DEFAULT_PARAMS_FORMAT = :yaml
|
8
|
-
DEFAULT_AUTO_EXPORT = false
|
9
|
-
|
10
|
-
SUPPORTED_ARRAY_MERGE_STRATEGIES = [:concat, :extend, :replace]
|
11
|
-
SUPPORTED_PARAMS_FORMATS = [:json, :yaml]
|
12
|
-
|
13
|
-
attr_reader :params_filename, :params_format,
|
14
|
-
:current_path, :user_path, :system_path,
|
15
|
-
:array_merge_strategy, :auto_export, :auto_export_script_path,
|
16
|
-
:key_error, :parse_error
|
17
|
-
|
18
|
-
attr_writer :array_merge_strategy, :auto_export, :auto_export_script_path
|
19
|
-
|
20
|
-
##
|
21
|
-
# Convenience method to easily accept either a hash that will
|
22
|
-
# be converted to a Nugrant::Config object or directly a config
|
23
|
-
# object.
|
24
|
-
def self.convert(config = {})
|
25
|
-
return config.kind_of?(Nugrant::Config) ? config : Nugrant::Config.new(config)
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# Return the fully expanded path of the user parameters
|
30
|
-
# default location that is used in the constructor.
|
31
|
-
#
|
32
|
-
def self.default_user_path()
|
33
|
-
File.expand_path("~")
|
34
|
-
end
|
35
|
-
|
36
|
-
##
|
37
|
-
# Return the fully expanded path of the system parameters
|
38
|
-
# default location that is used in the constructor.
|
39
|
-
#
|
40
|
-
def self.default_system_path()
|
41
|
-
if Config.on_windows?
|
42
|
-
return File.expand_path(ENV['PROGRAMDATA'] || ENV['ALLUSERSPROFILE'])
|
43
|
-
end
|
44
|
-
|
45
|
-
"/etc"
|
46
|
-
end
|
47
|
-
|
48
|
-
##
|
49
|
-
# Method to fix-up a received path. The fix-up do the follows
|
50
|
-
# the following rules:
|
51
|
-
#
|
52
|
-
# 1. If the path is callable, call it to get the value.
|
53
|
-
# 2. If value is nil, return default value.
|
54
|
-
# 3. If value is a directory, return path + params_filename to it.
|
55
|
-
# 4. Otherwise, return value
|
56
|
-
#
|
57
|
-
# @param path The path parameter received.
|
58
|
-
# @param default The default path to use, can be a directory.
|
59
|
-
# @param params_filename The params filename to append if path is a directory
|
60
|
-
#
|
61
|
-
# @return The fix-up path following rules defined above.
|
62
|
-
#
|
63
|
-
def self.fixup_path(path, default, params_filename)
|
64
|
-
path = path.call if path.respond_to?(:call)
|
65
|
-
|
66
|
-
path = File.expand_path(path || default)
|
67
|
-
path = "#{path}/#{params_filename}" if ::File.directory?(path)
|
68
|
-
|
69
|
-
path
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.supported_array_merge_strategy(strategy)
|
73
|
-
SUPPORTED_ARRAY_MERGE_STRATEGIES.include?(strategy)
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.supported_params_format(format)
|
77
|
-
SUPPORTED_PARAMS_FORMATS.include?(format)
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# Return true if we are currently on a Windows platform.
|
82
|
-
#
|
83
|
-
def self.on_windows?()
|
84
|
-
(RbConfig::CONFIG['host_os'].downcase =~ /mswin|mingw|cygwin/) != nil
|
85
|
-
end
|
86
|
-
|
87
|
-
##
|
88
|
-
# Creates a new config object that is used to configure an instance
|
89
|
-
# of Nugrant::Parameters. See the list of options and how they interact
|
90
|
-
# with Nugrant::Parameters.
|
91
|
-
#
|
92
|
-
# =| Options
|
93
|
-
# * +:params_filename+ - The filename used to fetch parameters from. This
|
94
|
-
# will be appended to various default locations.
|
95
|
-
# Location are system, project and current that
|
96
|
-
# can be tweaked individually by using the options
|
97
|
-
# below.
|
98
|
-
# Defaults => ".nuparams"
|
99
|
-
# * +:params_format+ - The format in which parameters are to be parsed.
|
100
|
-
# Presently supporting :yaml and :json.
|
101
|
-
# Defaults => :yaml
|
102
|
-
# * +:current_path+ - The current path has the highest precedence over
|
103
|
-
# any other location. It can be be used for many purposes
|
104
|
-
# depending on your usage.
|
105
|
-
# * A path from where to read project parameters
|
106
|
-
# * A path from where to read overriding parameters for a cli tool
|
107
|
-
# * A path from where to read user specific settings not to be committed in a VCS
|
108
|
-
# Defaults => "./#{@params_filename}"
|
109
|
-
# * +:user_path+ - The user path is the location where the user
|
110
|
-
# parameters should resides. The parameters loaded from this
|
111
|
-
# location have the second highest precedence.
|
112
|
-
# Defaults => "~/#{@params_filename}"
|
113
|
-
# * +:system_path+ - The system path is the location where system wide
|
114
|
-
# parameters should resides. The parameters loaded from this
|
115
|
-
# location have the third highest precedence.
|
116
|
-
# Defaults => Default system path depending on OS + @params_filename
|
117
|
-
# * +:array_merge_strategy+ - This option controls how array values are merged together when merging
|
118
|
-
# two Bag instances. Possible values are:
|
119
|
-
# * :replace => Replace current values by new ones
|
120
|
-
# * :extend => Merge current values with new ones
|
121
|
-
# * :concat => Append new values to current ones
|
122
|
-
# Defaults => The strategy :replace.
|
123
|
-
# * +:key_error+ - A callback method receiving one argument, the key as a symbol, and that
|
124
|
-
# deal with the error. If the callable does not
|
125
|
-
# raise an exception, the result of it's execution is returned.
|
126
|
-
# Defaults => A callable that throws a KeyError exception.
|
127
|
-
# * +:parse_error+ - A callback method receiving two arguments, the offending filename and
|
128
|
-
# the error object, that deal with the error. If the callable does not
|
129
|
-
# raise an exception, the result of it's execution is returned.
|
130
|
-
# Defaults => A callable that returns the empty hash.
|
131
|
-
# * +:auto_export+ - Automatically export configuration to the specified format :autoenv or :script
|
132
|
-
# * +:auto_export_script_path+ - The path where to write the export script, defaults to "./nugrant2env.sh"
|
133
|
-
#
|
134
|
-
def initialize(options = {})
|
135
|
-
@params_filename = options[:params_filename] || DEFAULT_PARAMS_FILENAME
|
136
|
-
@params_format = options[:params_format] || DEFAULT_PARAMS_FORMAT
|
137
|
-
@auto_export = options[:auto_export] || DEFAULT_AUTO_EXPORT
|
138
|
-
@auto_export_script_path = options[:auto_export_script_path] || false # use default
|
139
|
-
|
140
|
-
@current_path = Config.fixup_path(options[:current_path], ".", @params_filename)
|
141
|
-
@user_path = Config.fixup_path(options[:user_path], Config.default_user_path(), @params_filename)
|
142
|
-
@system_path = Config.fixup_path(options[:system_path], Config.default_system_path(), @params_filename)
|
143
|
-
|
144
|
-
@array_merge_strategy = options[:array_merge_strategy] || :replace
|
145
|
-
|
146
|
-
@key_error = options[:key_error] || Proc.new do |key|
|
147
|
-
raise KeyError, "Undefined parameter '#{key}'"
|
148
|
-
end
|
149
|
-
|
150
|
-
@parse_error = options[:parse_error] || Proc.new do |filename, error|
|
151
|
-
{}
|
152
|
-
end
|
153
|
-
|
154
|
-
validate()
|
155
|
-
end
|
156
|
-
|
157
|
-
def ==(other)
|
158
|
-
self.class.equal?(other.class) &&
|
159
|
-
instance_variables.all? do |variable|
|
160
|
-
instance_variable_get(variable) == other.instance_variable_get(variable)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def [](key)
|
165
|
-
instance_variable_get("@#{key}")
|
166
|
-
rescue
|
167
|
-
nil
|
168
|
-
end
|
169
|
-
|
170
|
-
def merge(other)
|
171
|
-
result = dup()
|
172
|
-
result.merge!(other)
|
173
|
-
end
|
174
|
-
|
175
|
-
def merge!(other)
|
176
|
-
other.instance_variables.each do |variable|
|
177
|
-
instance_variable_set(variable, other.instance_variable_get(variable)) if instance_variables.include?(variable)
|
178
|
-
end
|
179
|
-
|
180
|
-
self
|
181
|
-
end
|
182
|
-
|
183
|
-
def to_h()
|
184
|
-
Hash[instance_variables.map do |variable|
|
185
|
-
[variable[1..-1].to_sym, instance_variable_get(variable)]
|
186
|
-
end]
|
187
|
-
end
|
188
|
-
|
189
|
-
alias_method :to_hash, :to_h
|
190
|
-
|
191
|
-
def validate()
|
192
|
-
raise ArgumentError,
|
193
|
-
"Invalid value for :params_format. \
|
194
|
-
The format [#{@params_format}] is currently not supported." if not Config.supported_params_format(@params_format)
|
195
|
-
|
196
|
-
raise ArgumentError,
|
197
|
-
"Invalid value for :array_merge_strategy. \
|
198
|
-
The array merge strategy [#{@array_merge_strategy}] is currently not supported." if not Config.supported_array_merge_strategy(@array_merge_strategy)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
module Nugrant
|
4
|
+
class Config
|
5
|
+
DEFAULT_ARRAY_MERGE_STRATEGY = :replace
|
6
|
+
DEFAULT_PARAMS_FILENAME = ".nuparams"
|
7
|
+
DEFAULT_PARAMS_FORMAT = :yaml
|
8
|
+
DEFAULT_AUTO_EXPORT = false
|
9
|
+
|
10
|
+
SUPPORTED_ARRAY_MERGE_STRATEGIES = [:concat, :extend, :replace]
|
11
|
+
SUPPORTED_PARAMS_FORMATS = [:json, :yaml]
|
12
|
+
|
13
|
+
attr_reader :params_filename, :params_format,
|
14
|
+
:current_path, :user_path, :system_path,
|
15
|
+
:array_merge_strategy, :auto_export, :auto_export_script_path,
|
16
|
+
:key_error, :parse_error
|
17
|
+
|
18
|
+
attr_writer :array_merge_strategy, :auto_export, :auto_export_script_path
|
19
|
+
|
20
|
+
##
|
21
|
+
# Convenience method to easily accept either a hash that will
|
22
|
+
# be converted to a Nugrant::Config object or directly a config
|
23
|
+
# object.
|
24
|
+
def self.convert(config = {})
|
25
|
+
return config.kind_of?(Nugrant::Config) ? config : Nugrant::Config.new(config)
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Return the fully expanded path of the user parameters
|
30
|
+
# default location that is used in the constructor.
|
31
|
+
#
|
32
|
+
def self.default_user_path()
|
33
|
+
File.expand_path("~")
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Return the fully expanded path of the system parameters
|
38
|
+
# default location that is used in the constructor.
|
39
|
+
#
|
40
|
+
def self.default_system_path()
|
41
|
+
if Config.on_windows?
|
42
|
+
return File.expand_path(ENV['PROGRAMDATA'] || ENV['ALLUSERSPROFILE'])
|
43
|
+
end
|
44
|
+
|
45
|
+
"/etc"
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Method to fix-up a received path. The fix-up do the follows
|
50
|
+
# the following rules:
|
51
|
+
#
|
52
|
+
# 1. If the path is callable, call it to get the value.
|
53
|
+
# 2. If value is nil, return default value.
|
54
|
+
# 3. If value is a directory, return path + params_filename to it.
|
55
|
+
# 4. Otherwise, return value
|
56
|
+
#
|
57
|
+
# @param path The path parameter received.
|
58
|
+
# @param default The default path to use, can be a directory.
|
59
|
+
# @param params_filename The params filename to append if path is a directory
|
60
|
+
#
|
61
|
+
# @return The fix-up path following rules defined above.
|
62
|
+
#
|
63
|
+
def self.fixup_path(path, default, params_filename)
|
64
|
+
path = path.call if path.respond_to?(:call)
|
65
|
+
|
66
|
+
path = File.expand_path(path || default)
|
67
|
+
path = "#{path}/#{params_filename}" if ::File.directory?(path)
|
68
|
+
|
69
|
+
path
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.supported_array_merge_strategy(strategy)
|
73
|
+
SUPPORTED_ARRAY_MERGE_STRATEGIES.include?(strategy)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.supported_params_format(format)
|
77
|
+
SUPPORTED_PARAMS_FORMATS.include?(format)
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Return true if we are currently on a Windows platform.
|
82
|
+
#
|
83
|
+
def self.on_windows?()
|
84
|
+
(RbConfig::CONFIG['host_os'].downcase =~ /mswin|mingw|cygwin/) != nil
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Creates a new config object that is used to configure an instance
|
89
|
+
# of Nugrant::Parameters. See the list of options and how they interact
|
90
|
+
# with Nugrant::Parameters.
|
91
|
+
#
|
92
|
+
# =| Options
|
93
|
+
# * +:params_filename+ - The filename used to fetch parameters from. This
|
94
|
+
# will be appended to various default locations.
|
95
|
+
# Location are system, project and current that
|
96
|
+
# can be tweaked individually by using the options
|
97
|
+
# below.
|
98
|
+
# Defaults => ".nuparams"
|
99
|
+
# * +:params_format+ - The format in which parameters are to be parsed.
|
100
|
+
# Presently supporting :yaml and :json.
|
101
|
+
# Defaults => :yaml
|
102
|
+
# * +:current_path+ - The current path has the highest precedence over
|
103
|
+
# any other location. It can be be used for many purposes
|
104
|
+
# depending on your usage.
|
105
|
+
# * A path from where to read project parameters
|
106
|
+
# * A path from where to read overriding parameters for a cli tool
|
107
|
+
# * A path from where to read user specific settings not to be committed in a VCS
|
108
|
+
# Defaults => "./#{@params_filename}"
|
109
|
+
# * +:user_path+ - The user path is the location where the user
|
110
|
+
# parameters should resides. The parameters loaded from this
|
111
|
+
# location have the second highest precedence.
|
112
|
+
# Defaults => "~/#{@params_filename}"
|
113
|
+
# * +:system_path+ - The system path is the location where system wide
|
114
|
+
# parameters should resides. The parameters loaded from this
|
115
|
+
# location have the third highest precedence.
|
116
|
+
# Defaults => Default system path depending on OS + @params_filename
|
117
|
+
# * +:array_merge_strategy+ - This option controls how array values are merged together when merging
|
118
|
+
# two Bag instances. Possible values are:
|
119
|
+
# * :replace => Replace current values by new ones
|
120
|
+
# * :extend => Merge current values with new ones
|
121
|
+
# * :concat => Append new values to current ones
|
122
|
+
# Defaults => The strategy :replace.
|
123
|
+
# * +:key_error+ - A callback method receiving one argument, the key as a symbol, and that
|
124
|
+
# deal with the error. If the callable does not
|
125
|
+
# raise an exception, the result of it's execution is returned.
|
126
|
+
# Defaults => A callable that throws a KeyError exception.
|
127
|
+
# * +:parse_error+ - A callback method receiving two arguments, the offending filename and
|
128
|
+
# the error object, that deal with the error. If the callable does not
|
129
|
+
# raise an exception, the result of it's execution is returned.
|
130
|
+
# Defaults => A callable that returns the empty hash.
|
131
|
+
# * +:auto_export+ - Automatically export configuration to the specified format :autoenv or :script
|
132
|
+
# * +:auto_export_script_path+ - The path where to write the export script, defaults to "./nugrant2env.sh"
|
133
|
+
#
|
134
|
+
def initialize(options = {})
|
135
|
+
@params_filename = options[:params_filename] || DEFAULT_PARAMS_FILENAME
|
136
|
+
@params_format = options[:params_format] || DEFAULT_PARAMS_FORMAT
|
137
|
+
@auto_export = options[:auto_export] || DEFAULT_AUTO_EXPORT
|
138
|
+
@auto_export_script_path = options[:auto_export_script_path] || false # use default
|
139
|
+
|
140
|
+
@current_path = Config.fixup_path(options[:current_path], ".", @params_filename)
|
141
|
+
@user_path = Config.fixup_path(options[:user_path], Config.default_user_path(), @params_filename)
|
142
|
+
@system_path = Config.fixup_path(options[:system_path], Config.default_system_path(), @params_filename)
|
143
|
+
|
144
|
+
@array_merge_strategy = options[:array_merge_strategy] || :replace
|
145
|
+
|
146
|
+
@key_error = options[:key_error] || Proc.new do |key|
|
147
|
+
raise KeyError, "Undefined parameter '#{key}'"
|
148
|
+
end
|
149
|
+
|
150
|
+
@parse_error = options[:parse_error] || Proc.new do |filename, error|
|
151
|
+
{}
|
152
|
+
end
|
153
|
+
|
154
|
+
validate()
|
155
|
+
end
|
156
|
+
|
157
|
+
def ==(other)
|
158
|
+
self.class.equal?(other.class) &&
|
159
|
+
instance_variables.all? do |variable|
|
160
|
+
instance_variable_get(variable) == other.instance_variable_get(variable)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def [](key)
|
165
|
+
instance_variable_get("@#{key}")
|
166
|
+
rescue
|
167
|
+
nil
|
168
|
+
end
|
169
|
+
|
170
|
+
def merge(other)
|
171
|
+
result = dup()
|
172
|
+
result.merge!(other)
|
173
|
+
end
|
174
|
+
|
175
|
+
def merge!(other)
|
176
|
+
other.instance_variables.each do |variable|
|
177
|
+
instance_variable_set(variable, other.instance_variable_get(variable)) if instance_variables.include?(variable)
|
178
|
+
end
|
179
|
+
|
180
|
+
self
|
181
|
+
end
|
182
|
+
|
183
|
+
def to_h()
|
184
|
+
Hash[instance_variables.map do |variable|
|
185
|
+
[variable[1..-1].to_sym, instance_variable_get(variable)]
|
186
|
+
end]
|
187
|
+
end
|
188
|
+
|
189
|
+
alias_method :to_hash, :to_h
|
190
|
+
|
191
|
+
def validate()
|
192
|
+
raise ArgumentError,
|
193
|
+
"Invalid value for :params_format. \
|
194
|
+
The format [#{@params_format}] is currently not supported." if not Config.supported_params_format(@params_format)
|
195
|
+
|
196
|
+
raise ArgumentError,
|
197
|
+
"Invalid value for :array_merge_strategy. \
|
198
|
+
The array merge strategy [#{@array_merge_strategy}] is currently not supported." if not Config.supported_array_merge_strategy(@array_merge_strategy)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
data/lib/nugrant/helper/bag.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
require 'multi_json'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
require 'nugrant/bag'
|
5
|
-
|
6
|
-
module Nugrant
|
7
|
-
module Helper
|
8
|
-
module Bag
|
9
|
-
def self.read(filepath, filetype, config)
|
10
|
-
Nugrant::Bag.new(parse_data(filepath, filetype, config), config)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.restricted_keys()
|
14
|
-
Nugrant::Bag.instance_methods()
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def self.parse_data(filepath, filetype, config)
|
20
|
-
return if not File.
|
21
|
-
|
22
|
-
File.open(filepath, "rb") do |file|
|
23
|
-
return send("parse_#{filetype}", file)
|
24
|
-
end
|
25
|
-
rescue => error
|
26
|
-
config.parse_error.call(filepath, error)
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.parse_json(io)
|
30
|
-
MultiJson.load(io.read())
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.parse_yaml(io)
|
34
|
-
YAML.load(io.read())
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
require 'multi_json'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
require 'nugrant/bag'
|
5
|
+
|
6
|
+
module Nugrant
|
7
|
+
module Helper
|
8
|
+
module Bag
|
9
|
+
def self.read(filepath, filetype, config)
|
10
|
+
Nugrant::Bag.new(parse_data(filepath, filetype, config), config)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.restricted_keys()
|
14
|
+
Nugrant::Bag.instance_methods()
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.parse_data(filepath, filetype, config)
|
20
|
+
return if not File.exist?(filepath)
|
21
|
+
|
22
|
+
File.open(filepath, "rb") do |file|
|
23
|
+
return send("parse_#{filetype}", file)
|
24
|
+
end
|
25
|
+
rescue => error
|
26
|
+
config.parse_error.call(filepath, error)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.parse_json(io)
|
30
|
+
MultiJson.load(io.read())
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.parse_yaml(io)
|
34
|
+
YAML.load(io.read())
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|