Class: FormKeeper::Rule::Criteria::Field
- Inherits:
-
Object
- Object
- FormKeeper::Rule::Criteria::Field
- Defined in:
- lib/formkeeper.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
Instance Method Summary collapse
-
#initialize(criteria) ⇒ Field
constructor
A new instance of Field.
- #require_presence? ⇒ Boolean
Constructor Details
#initialize(criteria) ⇒ Field
Returns a new instance of Field.
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 538 539 540 541 542 |
# File 'lib/formkeeper.rb', line 509 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
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
508 509 510 |
# File 'lib/formkeeper.rb', line 508 def constraints @constraints end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
508 509 510 |
# File 'lib/formkeeper.rb', line 508 def default @default end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
508 509 510 |
# File 'lib/formkeeper.rb', line 508 def filters @filters end |
Instance Method Details
#require_presence? ⇒ Boolean
544 545 546 |
# File 'lib/formkeeper.rb', line 544 def require_presence? @present end |