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.
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
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
515 516 517 |
# File 'lib/formkeeper.rb', line 515 def constraints @constraints end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
515 516 517 |
# File 'lib/formkeeper.rb', line 515 def default @default end |
#filters ⇒ Object (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
551 552 553 |
# File 'lib/formkeeper.rb', line 551 def require_presence? @present end |