summaryrefslogtreecommitdiff
path: root/lib/leap_cli/config/object.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-06-04 23:06:10 -0700
committerelijah <elijah@riseup.net>2013-06-04 23:06:10 -0700
commit8f79b632aeeee1111087dee6ebb6302aca700bbd (patch)
tree647b24bee28b28301de6c4a82a916222cde491e8 /lib/leap_cli/config/object.rb
parenta46321a43318a9cd3e2dd645b64fe81b71e7f8ea (diff)
add support for `leap facts`. includes some fun new helpers, like run_with_progress(), capture(), and replace_file!().
Diffstat (limited to 'lib/leap_cli/config/object.rb')
-rw-r--r--lib/leap_cli/config/object.rb40
1 files changed, 1 insertions, 39 deletions
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index 4f348b3..b88c7b4 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -43,7 +43,7 @@ module LeapCli
def dump_json
evaluate
- generate_json(self)
+ JSON.sorted_generate(self)
end
def evaluate
@@ -278,44 +278,6 @@ module LeapCli
end
#
- # Output json from ruby objects in such a manner that all the hashes and arrays are output in alphanumeric sorted order.
- # This is required so that our generated configs don't throw puppet or git for a tizzy fit.
- #
- # Beware: some hacky stuff ahead.
- #
- # This relies on the pure ruby implementation of JSON.generate (i.e. require 'json/pure')
- # see https://github.com/flori/json/blob/master/lib/json/pure/generator.rb
- #
- # The Oj way that we are not using: Oj.dump(obj, :mode => :compat, :indent => 2)
- #
- def generate_json(obj)
- # modify hash and array
- Hash.class_eval do
- alias_method :each_without_sort, :each
- def each(&block)
- keys.sort {|a,b| a.to_s <=> b.to_s }.each do |key|
- yield key, self[key]
- end
- end
- end
- Array.class_eval do
- alias_method :each_without_sort, :each
- def each(&block)
- sort {|a,b| a.to_s <=> b.to_s }.each_without_sort &block
- end
- end
-
- # generate json
- return_value = JSON.pretty_generate(obj)
-
- # restore hash and array
- Hash.class_eval {alias_method :each, :each_without_sort}
- Array.class_eval {alias_method :each, :each_without_sort}
-
- return return_value
- end
-
- #
# when merging, we raise an error if this method returns true for the two values.
#
def type_mismatch?(old_value, new_value)