Sha256: e17d49d61ff7d6dfc1400457748be3d35db9f55cc0aaef9d2463421ba0e77e4b

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true
# author: Vadim Shaveiko <@vshaveyko>
class RailsApiDoc::Controller::Parameter::Repository::Param

  ACCEPTED_TYPES = [String, Integer, Object, Array, DateTime, :enum, :model].freeze

  # @type - type to check
  def self.accepted_nested_type?(type)
    type == Object || type == :model
  end

  def self.valid_type?(type)
    return if type.in?(ACCEPTED_TYPES)
    raise ArgumentError, "Wrong type: #{type}. " \
                         "Correct types are: #{ACCEPTED_TYPES}."
  end

  def self.valid_enum?(enum)
    return if enum.nil? || enum.is_a?(Array)
    raise ArgumentError, 'Enum must be an array.'
  end

  def self.valid_nested?(type, block_given)
    return false unless accepted_nested_type?(type)
    return true if block_given
    raise ArgumentError, 'Empty object passed.'
  end

  def initialize(name, store)
    @name = name
    @store = store
  end

  def nested?
    self.class.accepted_nested_type?(@store[:type])
  end

  def required?
    @store[:required]
  end

  def method_missing(name, *args)
    return @store.send(name, *args) if respond_to_missing?(name)
    super
  end

  def respond_to_missing?(name)
    @store.respond_to?(name)
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_api_documentation-0.1.6 lib/rails_api_doc/controller/parameter/repository/param.rb
rails_api_documentation-0.1.5 lib/rails_api_doc/controller/parameter/repository/param.rb
rails_api_documentation-0.1.4 lib/rails_api_doc/controller/parameter/repository/param.rb
rails_api_documentation-0.1.3 lib/rails_api_doc/controller/parameter/repository/param.rb
rails_api_documentation-0.1.2 lib/rails_api_doc/controller/parameter/repository/param.rb
rails_api_documentation-0.1.1 lib/rails_api_doc/controller/parameter/repository/param.rb
rails_api_documentation-0.1.0 lib/rails_api_doc/controller/parameter/repository/param.rb