Class: FormKeeper::Rule::Criteria::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/formkeeper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(criteria) ⇒ Field

Returns a new instance of Field.



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/formkeeper.rb', line 516

def initialize(criteria)
  if criteria.has_key?(:default)
    default = criteria.delete :default
    @default = default.empty? ? nil : default
  else
    @default = nil
  end
  if criteria.has_key?(:filters)
    filters = criteria.delete :filters
    case filters
    when Array
      @filters = filters.collect(&:to_sym)
    when String
      @filters = [filters.to_sym]
    when Symbol
      @filters = [filters]
    else
      raise ArgumentError.new 'invalid :filters'
    end
  else
    @filters = []
  end

  if criteria.has_key?(:present)
    if not @default.nil?
      raise ArgumentError.new "don't set both :default and :present at once"
    end
    present = criteria.delete :present
    @present = !!present
  else
    @present = false
  end
  @constraints = criteria
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



515
516
517
# File 'lib/formkeeper.rb', line 515

def constraints
  @constraints
end

#defaultObject (readonly)

Returns the value of attribute default.



515
516
517
# File 'lib/formkeeper.rb', line 515

def default
  @default
end

#filtersObject (readonly)

Returns the value of attribute filters.



515
516
517
# File 'lib/formkeeper.rb', line 515

def filters
  @filters
end

Instance Method Details

#require_presence?Boolean

Returns:

  • (Boolean)


551
552
553
# File 'lib/formkeeper.rb', line 551

def require_presence?
  @present
end