Sha256: b075bbc8268513f55c138614843f1f722b4d707437b6b9b60d142c093dedb746

Contents?: true

Size: 931 Bytes

Versions: 64

Compression:

Stored size: 931 Bytes

Contents

class Rack::App::Middlewares::Params::Definition::Options

  ERROR_EACH = 'class must implement #each method to use :of expression in parameter definition'

  def initialize(descriptor)
    @descriptor = descriptor
  end

  def formatted
    {
      :class => parameter_class,
      :of => parameter_class_elements,
      :description => parameter_description,
      :example => parameter_example
    }
  end

  protected

  def parameter_example
    @descriptor[:example] 
  end

  def parameter_description
    @descriptor[:desc] || @descriptor[:description]
  end

  def parameter_class
    @descriptor[:class] || @descriptor[:type]
  end

  def parameter_class_elements
    if @descriptor[:of]
      raise "#{parameter_class} #{ERROR_EACH}" unless parameter_class_iterable?
      @descriptor[:of]
    end
  end

  def parameter_class_iterable?
    parameter_class.instance_method(:each)
  rescue NameError
    false
  end

end

Version data entries

64 entries across 64 versions & 2 rubygems

Version Path
rack-app-11.0.2 lib/rack/app/middlewares/params/definition/options.rb
rack-app-11.0.1 lib/rack/app/middlewares/params/definition/options.rb
rack-app-11.0.0 lib/rack/app/middlewares/params/definition/options.rb
rack-app-10.0.0 lib/rack/app/middlewares/params/definition/options.rb
rack-app-9.0.0 lib/rack/app/middlewares/params/definition/options.rb
rack-app-8.1.0 lib/rack/app/middlewares/params/definition/options.rb
rack-app-8.0.1 lib/rack/app/middlewares/params/definition/options.rb
rack-app-8.0.0 lib/rack/app/middlewares/params/definition/options.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.7.0 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.6.5 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.6.4 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.6.3 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.6.2 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.6.1 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.6.0 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.5.2 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.5.1 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.5.0 lib/rack/app/middlewares/params/definition/options.rb
rack-app-7.4.0 lib/rack/app/middlewares/params/definition/options.rb