Sha256: 474ebf0d93c580c5e0cbcacd9c37ce16d1953695bed01bec7a40bda988d97472

Contents?: true

Size: 795 Bytes

Versions: 2

Compression:

Stored size: 795 Bytes

Contents

class Betterdocs::Dsl::JsonParams::Param < Betterdocs::Dsl::Representer
  extend Tins::DSLAccessor
  include Betterdocs::Dsl::Common
  include Betterdocs::Dsl::Naming

  dsl_accessor :description, 'TODO'

  dsl_accessor :value, 'TODO'

  dsl_accessor :types do [] end

  dsl_accessor :required, true

  def initialize(representer, name, options, &block)
    super
    types Betterdocs::Dsl::JsonTypeMapper.map_types(types)
  end

  def assign(result, object)
    assign?(object) or return
    result[name] = compute_value(object)
  end

  def compute_value(object)
    value = object.__send__(name)
    if ActiveSupport::TimeWithZone === value
      value.extend Betterdocs::JsonTimeWithZone
    end
    value
  end

  def add_to_collector(collector)
    collector.params[name] = self
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
betterdocs-0.4.0 lib/betterdocs/dsl/json_params/param.rb
betterdocs-0.3.0 lib/betterdocs/dsl/json_params/param.rb