Class: FormKeeper::Rule
- Inherits:
-
Object
- Object
- FormKeeper::Rule
- Defined in:
- lib/formkeeper.rb
Defined Under Namespace
Modules: Criteria
Instance Attribute Summary collapse
-
#checkboxes ⇒ Object
readonly
Returns the value of attribute checkboxes.
-
#combinations ⇒ Object
readonly
Returns the value of attribute combinations.
-
#default_filters ⇒ Object
readonly
Returns the value of attribute default_filters.
-
#encoding_filter ⇒ Object
readonly
Returns the value of attribute encoding_filter.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #combination(name, criteria) ⇒ Object
- #encoding(code) ⇒ Object
- #field(name, criteria) ⇒ Object
- #filters(*args) ⇒ Object
-
#initialize ⇒ Rule
constructor
A new instance of Rule.
- #method_missing(name, *args) ⇒ Object
- #selection(name, criteria) ⇒ Object (also: #checkbox)
Constructor Details
#initialize ⇒ Rule
Returns a new instance of Rule.
632 633 634 635 636 637 638 |
# File 'lib/formkeeper.rb', line 632 def initialize @default_filters = [] @encoding_filter = nil @fields = {} @checkboxes = {} @combinations = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/formkeeper.rb', line 666 def method_missing(name, *args) rule = args[0] criteria = {} criteria[:fields] = args[1] opts = args[2] || {} if opts.has_key?(:filters) criteria[:filters] = opts.delete(:filters) end if opts.empty? criteria[name.to_sym] = true else criteria[name.to_sym] = opts end combination(rule, criteria) end |
Instance Attribute Details
#checkboxes ⇒ Object (readonly)
Returns the value of attribute checkboxes.
630 631 632 |
# File 'lib/formkeeper.rb', line 630 def checkboxes @checkboxes end |
#combinations ⇒ Object (readonly)
Returns the value of attribute combinations.
630 631 632 |
# File 'lib/formkeeper.rb', line 630 def combinations @combinations end |
#default_filters ⇒ Object (readonly)
Returns the value of attribute default_filters.
630 631 632 |
# File 'lib/formkeeper.rb', line 630 def default_filters @default_filters end |
#encoding_filter ⇒ Object (readonly)
Returns the value of attribute encoding_filter.
630 631 632 |
# File 'lib/formkeeper.rb', line 630 def encoding_filter @encoding_filter end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
630 631 632 |
# File 'lib/formkeeper.rb', line 630 def fields @fields end |
Instance Method Details
#combination(name, criteria) ⇒ Object
661 662 663 664 |
# File 'lib/formkeeper.rb', line 661 def combination(name, criteria) raise ArgumentError.new unless criteria.kind_of?(Hash) @combinations[name.to_sym] = Criteria::Combination.new(criteria) end |
#encoding(code) ⇒ Object
640 641 642 |
# File 'lib/formkeeper.rb', line 640 def encoding(code) @encoding_filter = Filter::ToUTF8.new(code) end |
#field(name, criteria) ⇒ Object
648 649 650 651 |
# File 'lib/formkeeper.rb', line 648 def field(name, criteria) raise ArgumentError.new unless criteria.kind_of?(Hash) @fields[name.to_sym] = Criteria::Field.new(criteria) end |
#filters(*args) ⇒ Object
644 645 646 |
# File 'lib/formkeeper.rb', line 644 def filters(*args) @default_filters = args end |