lib/schematic/generator/column.rb in schematic-0.6.1 vs lib/schematic/generator/column.rb in schematic-0.6.2

- old
+ new

@@ -6,16 +6,17 @@ def restriction_classes @restriction_classes ||= [Restrictions::Length, Restrictions::Enumeration, Restrictions::Numericality, Restrictions::Pattern, Restrictions::Custom] end end - def initialize(klass, column, additional_methods = {}, ignored_methods = {}, required_methods = []) + def initialize(klass, column, additional_methods = {}, ignored_methods = {}, required_methods = [], non_required_methods = []) @klass = klass @column = column @additional_methods = additional_methods @ignored_methods = ignored_methods @required_methods = required_methods + @non_required_methods = non_required_methods end def generate(builder) return if skip_generation? @@ -38,9 +39,10 @@ end end end def minimum_occurrences_for_column + return 0 if @non_required_methods.include?(@column.name.to_sym) return 1 if @required_methods.include?(@column.name.to_sym) return 0 unless @klass.respond_to?(:_validators) @klass._validators[@column.name.to_sym].each do |column_validation| next unless column_validation.is_a? ActiveModel::Validations::PresenceValidator if column_validation.options[:allow_blank] != true &&