diff options
| author | elijah <elijah@riseup.net> | 2014-11-24 22:45:27 -0800 | 
|---|---|---|
| committer | elijah <elijah@riseup.net> | 2014-11-24 22:45:27 -0800 | 
| commit | b839376a507e37a048ea2df53127ed0884310f60 (patch) | |
| tree | 68ba30a77c51a3ee1a2c9ddd7187e6743cff08f1 /lib/core_ext | |
| parent | 8450768268c2bdf82cd6d6bfa9972c70bc5cdcac (diff) | |
moved core_ext and lib_ext under leap_cli
Diffstat (limited to 'lib/core_ext')
| -rw-r--r-- | lib/core_ext/boolean.rb | 14 | ||||
| -rw-r--r-- | lib/core_ext/hash.rb | 35 | ||||
| -rw-r--r-- | lib/core_ext/json.rb | 42 | ||||
| -rw-r--r-- | lib/core_ext/nil.rb | 5 | ||||
| -rw-r--r-- | lib/core_ext/string.rb | 14 | ||||
| -rw-r--r-- | lib/core_ext/yaml.rb | 29 | 
6 files changed, 0 insertions, 139 deletions
| diff --git a/lib/core_ext/boolean.rb b/lib/core_ext/boolean.rb deleted file mode 100644 index 9b617b2..0000000 --- a/lib/core_ext/boolean.rb +++ /dev/null @@ -1,14 +0,0 @@ -# -# make is_a?(Boolean) possible. -# - -module Boolean -end - -class TrueClass -  include Boolean -end - -class FalseClass -  include Boolean -end
\ No newline at end of file diff --git a/lib/core_ext/hash.rb b/lib/core_ext/hash.rb deleted file mode 100644 index 7df33b2..0000000 --- a/lib/core_ext/hash.rb +++ /dev/null @@ -1,35 +0,0 @@ -class Hash - -  ## -  ## CONVERTING -  ## - -  # -  # convert self into a hash, but only include the specified keys -  # -  def pick(*keys) -    keys.map(&:to_s).inject({}) do |hsh, key| -      if has_key?(key) -        hsh[key] = self[key] -      end -      hsh -    end -  end - -  # -  # recursive merging (aka deep merge) -  # taken from ActiveSupport::CoreExtensions::Hash::DeepMerge -  # -  def deep_merge(other_hash) -    self.merge(other_hash) do |key, oldval, newval| -      oldval = oldval.to_hash if oldval.respond_to?(:to_hash) -      newval = newval.to_hash if newval.respond_to?(:to_hash) -      oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval -    end -  end - -  def deep_merge!(other_hash) -    replace(deep_merge(other_hash)) -  end - -end diff --git a/lib/core_ext/json.rb b/lib/core_ext/json.rb deleted file mode 100644 index 1a82bd9..0000000 --- a/lib/core_ext/json.rb +++ /dev/null @@ -1,42 +0,0 @@ -module JSON -  # -  # 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 self.sorted_generate(obj) -    # modify hash and array -    Array.class_eval do -      alias_method :each_without_sort, :each -      def each(&block) -        sorted = sort {|a,b| a.to_s <=> b.to_s } -        for i in 0..(sorted.length-1) do -          yield sorted[i] -        end -      end -    end -    Hash.class_eval do -      alias_method :each_without_sort, :each -      def each(&block) -        self.keys.each do |key| -          yield key, self.fetch(key) # fetch is used so we don't trigger Config::Object auto-eval -        end -      end -    end - -    # generate json -    json_str = 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 json_str -  end -end diff --git a/lib/core_ext/nil.rb b/lib/core_ext/nil.rb deleted file mode 100644 index 05ca98f..0000000 --- a/lib/core_ext/nil.rb +++ /dev/null @@ -1,5 +0,0 @@ -class NilClass -  def any? -    false -  end -end
\ No newline at end of file diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb deleted file mode 100644 index 07af8e5..0000000 --- a/lib/core_ext/string.rb +++ /dev/null @@ -1,14 +0,0 @@ -# -# make ruby 1.9 act more like ruby 1.8 -# -unless String.method_defined?(:to_a) -  class String -    def to_a; [self]; end -  end -end - -unless String.method_defined?(:any?) -  class String -    def any?; self.chars.any?; end -  end -end diff --git a/lib/core_ext/yaml.rb b/lib/core_ext/yaml.rb deleted file mode 100644 index bb0b5c9..0000000 --- a/lib/core_ext/yaml.rb +++ /dev/null @@ -1,29 +0,0 @@ -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 | 
