frameit/lib/frameit/config_parser.rb in fastlane-2.142.0 vs frameit/lib/frameit/config_parser.rb in fastlane-2.143.0

- old
+ new

@@ -1,6 +1,6 @@ -require_relative 'module' +require_relative 'device_types' module Frameit class ConfigParser attr_reader :data @@ -77,17 +77,11 @@ def validate_key(key, value) case key when 'font' UI.user_error!("Could not find font at path '#{File.expand_path(value)}'") unless File.exist?(value) when 'fonts' - UI.user_error!("`fonts` must be an array") unless value.kind_of?(Array) - - value.each do |current| - UI.user_error!("You must specify a font path") if current.fetch('font', '').length == 0 - UI.user_error!("Could not find font at path '#{File.expand_path(current.fetch('font'))}'") unless File.exist?(current.fetch('font')) - UI.user_error!("`supported` must be an array") unless current.fetch('supported', []).kind_of?(Array) - end + check_fonts(value) when 'background' UI.user_error!("Could not find background image at path '#{File.expand_path(value)}'") unless File.exist?(value) when 'color' UI.user_error!("Invalid color '#{value}'. Must be valid Hex #123123") unless value.include?("#") when 'padding' @@ -101,14 +95,42 @@ when 'show_complete_frame', 'title_below_image' UI.user_error!("'#{key}' must be a Boolean") unless [true, false].include?(value) when 'font_scale_factor' UI.user_error!("font_scale_factor must be numeric") unless value.kind_of?(Numeric) when 'frame' - UI.user_error!("device must be BLACK, WHITE, GOLD, ROSE_GOLD") unless ["BLACK", "WHITE", "GOLD", "ROSE_GOLD"].include?(value) + UI.user_error!("Invalid frame color '#{value}'. Frame color must be one of " + Color.all_colors.join(', ')) unless ConfigParser.supported_color?(value) + when 'use_platform' + UI.user_error!("Invalid platform type '#{value}'. Available values are " + Platform.all_platforms.join(', ') + ".") unless ConfigParser.supported_platform?(value) + when 'force_device_type' + UI.user_error!("Invalid device type '#{value}'. Available values: " + Devices.all_device_names_without_apple.join(', ')) unless ConfigParser.supported_device?(value) end end + def check_fonts(value) + UI.user_error!("`fonts` must be an array") unless value.kind_of?(Array) + + value.each do |current| + UI.user_error!("You must specify a font path") if current.fetch('font', '').length == 0 + UI.user_error!("Could not find font at path '#{File.expand_path(current.fetch('font'))}'") unless File.exist?(current.fetch('font')) + UI.user_error!("`supported` must be an array") unless current.fetch('supported', []).kind_of?(Array) + end + end + def integer_or_percentage(value) value.kind_of?(Integer) || (value.end_with?('%') && value.to_f > 0) + end + + def self.supported_color?(value) + return false if value.nil? + Color.all_colors.any? { |c| c == value } + end + + def self.supported_platform?(value) + return false if value.nil? + Platform.all_platforms.any? { |c| c == value } + end + + def self.supported_device?(value) + return !Device.find_device_by_id_or_name(value).nil? end end end