Sha256: 2fefeb8782fe1c27013643e3d7084620b780285f382e8f1b90f05d9cb3fe928c

Contents?: true

Size: 818 Bytes

Versions: 8

Compression:

Stored size: 818 Bytes

Contents

class Object
  #
  # ya2yaml will output hash keys in sorted order, but it outputs arrays
  # in natural order. This new method, sorted_ya2yaml(), is the same as
  # ya2yaml but ensures that arrays are sorted.
  #
  # This is important so that the .yaml files don't change each time you recompile.
  #
  # see https://github.com/afunai/ya2yaml/blob/master/lib/ya2yaml.rb
  #
  def sorted_ya2yaml(options = {})
    # modify array
    Array.class_eval do
      alias_method :collect_without_sort, :collect
      def collect(&block)
        sorted = sort {|a,b| a.to_s <=> b.to_s}
        sorted.collect_without_sort(&block)
      end
    end

    # generate yaml
    yaml_str = self.ya2yaml(options)

    # restore array
    Array.class_eval {alias_method :collect, :collect_without_sort}

    return yaml_str
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
leap_cli-1.9.2 lib/leap_cli/core_ext/yaml.rb
leap_cli-1.9.1 lib/leap_cli/core_ext/yaml.rb
leap_cli-1.9 lib/leap_cli/core_ext/yaml.rb
leap_cli-1.8.1 lib/leap_cli/core_ext/yaml.rb
leap_cli-1.8 lib/leap_cli/core_ext/yaml.rb
leap_cli-1.7.4 lib/leap_cli/core_ext/yaml.rb
leap_cli-1.7.3 lib/leap_cli/core_ext/yaml.rb
leap_cli-1.6.2 lib/leap_cli/core_ext/yaml.rb