Sha256: 9f299cd1715748e873bb1082a9cfea9f44d648d6dcfbba7e9096d8895d60a876

Contents?: true

Size: 676 Bytes

Versions: 11

Compression:

Stored size: 676 Bytes

Contents

module Spectifly
  module Json
    class Field < Spectifly::Base::Field
      def to_h
        fields = {
          :type => type,
          :multiple => multiple?,
          :required => required?,
        }
        [:description, :example, :validations, :restrictions].each do |opt|
          value = self.send(opt)
          if value && !value.empty?
            fields[opt] = value
          end
        end
        { name.to_sym => fields}
      end

      def restrictions
        @restrictions.inject({}) do |result, (type, value)|
          value = value.source if type == 'regex'
          result[type] = value
          result
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spectifly-0.0.11 lib/spectifly/json/field.rb
spectifly-0.0.10 lib/spectifly/json/field.rb
spectifly-0.0.9 lib/spectifly/json/field.rb
spectifly-0.0.8 lib/spectifly/json/field.rb
spectifly-0.0.7 lib/spectifly/json/field.rb
spectifly-0.0.6 lib/spectifly/json/field.rb
spectifly-0.0.5 lib/spectifly/json/field.rb
spectifly-0.0.4 lib/spectifly/json/field.rb
spectifly-0.0.3 lib/spectifly/json/field.rb
spectifly-0.0.2 lib/spectifly/json/field.rb
spectifly-0.0.1 lib/spectifly/json/field.rb