Sha256: b05165e738c6178683a0a34a0c19649d065f205e38fca31ad21b49918ce1fea6

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

module Spontaneous::Rack::Back
  class Field < Base
    # Should be a GET as it changes no state but the request can need a lot
    # of data which is best done outside of the query string
    post '/conflicts/:id/?:box_id?' do
      content_for_request(true) do |content, box|
        generate_conflict_list(box || content)
      end
    end

    get '/options/:field_sid/:id/?:box_id?' do
      content_for_request do |content, box|
        field = (box || content).fields.sid(params[:field_sid])
        json(field.option_list)
      end
    end

    def generate_conflict_list(content)
      field_versions = params[:fields]
      conflicts = []
      field_versions.each do |schema_id, version|
        field = content.fields.sid(schema_id)
        if field.matches_version?(version.to_i)
          conflicts << field
        end
      end
      if conflicts.empty?
        200
      else
        errors = conflicts.map  do |field|
          [field.schema_id.to_s, [field.version, field.conflicted_value]]
        end
        [409, json(Hash[errors])]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/rack/back/field.rb
spontaneous-0.2.0.beta9 lib/spontaneous/rack/back/field.rb
spontaneous-0.2.0.beta8 lib/spontaneous/rack/back/field.rb
spontaneous-0.2.0.beta7 lib/spontaneous/rack/back/field.rb
spontaneous-0.2.0.beta6 lib/spontaneous/rack/back/field.rb
spontaneous-0.2.0.beta5 lib/spontaneous/rack/back/field.rb
spontaneous-0.2.0.beta4 lib/spontaneous/rack/back/field.rb
spontaneous-0.2.0.beta3 lib/spontaneous/rack/back/field.rb
spontaneous-0.2.0.beta2 lib/spontaneous/rack/back/field.rb