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.



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/formkeeper.rb', line 504

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.



503
504
505
# File 'lib/formkeeper.rb', line 503

def constraints
  @constraints
end

#defaultObject (readonly)

Returns the value of attribute default.



503
504
505
# File 'lib/formkeeper.rb', line 503

def default
  @default
end

#filtersObject (readonly)

Returns the value of attribute filters.



503
504
505
# File 'lib/formkeeper.rb', line 503

def filters
  @filters
end

Instance Method Details

#require_presence?Boolean

Returns:

  • (Boolean)


539
540
541
# File 'lib/formkeeper.rb', line 539

def require_presence?
  @present
end