Sha256: e352e22f015ea943015806c9c1e0c5adb91b1514528bd2a042d402643b4c01b9

Contents?: true

Size: 1.01 KB

Versions: 37

Compression:

Stored size: 1.01 KB

Contents

module Katello
  module Util
    module Data
      def self.array_with_indifferent_access(variable)
        variable.map { |x| x.with_indifferent_access }
      end

      def self.ostructize(obj, options = {})
        options[:prefix_keys] ||= []
        options[:prefix] ||= '_'

        if obj.is_a? Hash

          ostructized_hash = {}
          obj.each do |key, value|
            if options[:prefix_keys].include? key
              new_key = (options[:prefix].to_s + key.to_s).to_sym
            else
              new_key = key
            end

            if Object.respond_to? new_key
              fail "Error occured while converting Hash to OpenStruct. Key '%s' conflicts with method OpenStruct#%s." % [new_key, new_key]
            end

            ostructized_hash[new_key] = ostructize(value, options)
          end
          return OpenStruct.new ostructized_hash

        elsif obj.is_a? Array

          return obj.map { |r| ostructize(r, options) }

        end
        return obj
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
katello-3.4.5 app/lib/katello/util/data.rb
katello-3.4.4 app/lib/katello/util/data.rb
katello-3.4.2 app/lib/katello/util/data.rb
katello-3.4.1 app/lib/katello/util/data.rb
katello-3.4.0.2 app/lib/katello/util/data.rb
katello-3.4.0.1 app/lib/katello/util/data.rb
katello-3.3.2 app/lib/katello/util/data.rb
katello-3.4.0 app/lib/katello/util/data.rb
katello-3.4.0.rc2 app/lib/katello/util/data.rb
katello-3.4.0.rc1 app/lib/katello/util/data.rb
katello-3.3.1.1 app/lib/katello/util/data.rb
katello-3.3.1 app/lib/katello/util/data.rb
katello-3.3.0.1 app/lib/katello/util/data.rb
katello-3.3.0 app/lib/katello/util/data.rb
katello-3.3.0.rc2 app/lib/katello/util/data.rb
katello-3.3.0.rc1.1 app/lib/katello/util/data.rb
katello-3.3.0.rc1 app/lib/katello/util/data.rb
katello-3.2.1.1 app/lib/katello/util/data.rb
katello-3.2.1 app/lib/katello/util/data.rb
katello-3.2.0 app/lib/katello/util/data.rb