17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/view_model/controller/migration_versions.rb', line 17
def specified_migration_versions
@specified_migration_versions ||=
begin
version_spec =
if params.include?(:versions)
params[:versions]
elsif request..include?(MIGRATION_VERSION_HEADER)
begin
JSON.parse(request.[MIGRATION_VERSION_HEADER])
rescue JSON::ParserError
raise ViewModel::Error.new(status: 400, detail: "Invalid JSON in #{MIGRATION_VERSION_HEADER}")
end
else
{}
end
versions =
IknowParams::Parser.parse_value(
version_spec,
with: IknowParams::Serializer::HashOf.new(
IknowParams::Serializer::String, IknowParams::Serializer::Integer))
migration_versions = {}
versions.each do |view_name, required_version|
viewmodel_class = ViewModel::Registry.for_view_name(view_name)
migration_versions[viewmodel_class] = required_version
rescue ViewModel::DeserializationError::UnknownView
next
end
migration_versions.freeze
end
end
|