lib/schemacop/v3/string_node.rb in schemacop-3.0.8 vs lib/schemacop/v3/string_node.rb in schemacop-3.0.9

- old
+ new

@@ -20,11 +20,11 @@ number: /^-?[0-9]+(\.[0-9]+)?$/ }.freeze # rubocop:enable Layout/LineLength def self.allowed_options - super + ATTRIBUTES + %i[format_options pattern] + super + ATTRIBUTES + %i[format_options pattern allow_blank] end def allowed_types { String => :string } end @@ -37,10 +37,16 @@ process_json(ATTRIBUTES, json) end def _validate(data, result:) super_data = super + + # Validate blank # + if options[:allow_blank].is_a?(FalseClass) && super_data.blank? + result.error 'String is blank but must not be blank!' + end + return if super_data.nil? # Validate length # length = super_data.size @@ -74,10 +80,10 @@ end end end def cast(value) - if value.present? + if !value.nil? to_cast = value elsif default.present? to_cast = default else return nil