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.
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
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
503 504 505 |
# File 'lib/formkeeper.rb', line 503 def constraints @constraints end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
503 504 505 |
# File 'lib/formkeeper.rb', line 503 def default @default end |
#filters ⇒ Object (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
539 540 541 |
# File 'lib/formkeeper.rb', line 539 def require_presence? @present end |