lib/nugrant/config.rb in nugrant-2.0.0.pre2 vs lib/nugrant/config.rb in nugrant-2.0.0.rc1
- old
+ new
@@ -123,9 +123,43 @@
end
validate()
end
+ def ==(other)
+ self.class.equal?(other.class) &&
+ instance_variables.all? do |variable|
+ instance_variable_get(variable) == other.instance_variable_get(variable)
+ end
+ end
+
+ def [](key)
+ instance_variable_get("@#{key}")
+ rescue
+ nil
+ end
+
+ def merge(other)
+ result = dup()
+ result.merge!(other)
+ end
+
+ def merge!(other)
+ other.instance_variables.each do |variable|
+ instance_variable_set(variable, other.instance_variable_get(variable)) if instance_variables.include?(variable)
+ end
+
+ self
+ end
+
+ def to_h()
+ Hash[instance_variables.map do |variable|
+ [variable[1..-1].to_sym, instance_variable_get(variable)]
+ end]
+ end
+
+ alias_method :to_hash, :to_h
+
def validate()
raise ArgumentError,
"Invalid value for :params_format. \
The format [#{@params_format}] is currently not supported." if not Config.supported_params_format(@params_format)