Sha256: 104086f24bf7e73c580379968495c444a2c8b222d426562219511f720ae537a3

Contents?: true

Size: 605 Bytes

Versions: 21

Compression:

Stored size: 605 Bytes

Contents

module SoapyCake
  module Helper
    def walk_tree(obj, key = nil, &block)
      return nil if obj == {}

      case obj
      when Hash
        obj.map { |hk, hv| [hk, walk_tree(hv, hk, &block)] }.to_h
      when Array
        obj.map { |av| walk_tree(av, &block) }
      else
        yield(obj, key)
      end
    end

    def validate_id(opts, key)
      fail Error, "Parameter '#{key}' must be > 0!" if opts[key].to_i < 1
    end

    def require_params(opts, params)
      params.each do |param|
        fail Error, "Parameter '#{param}' missing!" unless opts.key?(param)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
soapy_cake-1.6.8 lib/soapy_cake/helper.rb
soapy_cake-1.6.7 lib/soapy_cake/helper.rb
soapy_cake-1.6.6 lib/soapy_cake/helper.rb
soapy_cake-1.6.5 lib/soapy_cake/helper.rb
soapy_cake-1.6.4 lib/soapy_cake/helper.rb
soapy_cake-1.6.3 lib/soapy_cake/helper.rb
soapy_cake-1.6.2 lib/soapy_cake/helper.rb
soapy_cake-1.6.1 lib/soapy_cake/helper.rb
soapy_cake-1.6.0 lib/soapy_cake/helper.rb
soapy_cake-1.5.2 lib/soapy_cake/helper.rb
soapy_cake-1.5.1 lib/soapy_cake/helper.rb
soapy_cake-1.5.0 lib/soapy_cake/helper.rb
soapy_cake-1.4.0 lib/soapy_cake/helper.rb
soapy_cake-1.3.6 lib/soapy_cake/helper.rb
soapy_cake-1.3.5 lib/soapy_cake/helper.rb
soapy_cake-1.3.4 lib/soapy_cake/helper.rb
soapy_cake-1.3.3 lib/soapy_cake/helper.rb
soapy_cake-1.3.2 lib/soapy_cake/helper.rb
soapy_cake-1.3.1 lib/soapy_cake/helper.rb
soapy_cake-1.3.0 lib/soapy_cake/helper.rb