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.
644 645 646 647 648 649 650 |
# File 'lib/formkeeper.rb', line 644 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
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/formkeeper.rb', line 678 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.
642 643 644 |
# File 'lib/formkeeper.rb', line 642 def checkboxes @checkboxes end |
#combinations ⇒ Object (readonly)
Returns the value of attribute combinations.
642 643 644 |
# File 'lib/formkeeper.rb', line 642 def combinations @combinations end |
#default_filters ⇒ Object (readonly)
Returns the value of attribute default_filters.
642 643 644 |
# File 'lib/formkeeper.rb', line 642 def default_filters @default_filters end |
#encoding_filter ⇒ Object (readonly)
Returns the value of attribute encoding_filter.
642 643 644 |
# File 'lib/formkeeper.rb', line 642 def encoding_filter @encoding_filter end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
642 643 644 |
# File 'lib/formkeeper.rb', line 642 def fields @fields end |
Instance Method Details
#combination(name, criteria) ⇒ Object
673 674 675 676 |
# File 'lib/formkeeper.rb', line 673 def combination(name, criteria) raise ArgumentError.new unless criteria.kind_of?(Hash) @combinations[name.to_sym] = Criteria::Combination.new(criteria) end |
#encoding(code) ⇒ Object
652 653 654 |
# File 'lib/formkeeper.rb', line 652 def encoding(code) @encoding_filter = Filter::ToUTF8.new(code) end |
#field(name, criteria) ⇒ Object
660 661 662 663 |
# File 'lib/formkeeper.rb', line 660 def field(name, criteria) raise ArgumentError.new unless criteria.kind_of?(Hash) @fields[name.to_sym] = Criteria::Field.new(criteria) end |
#filters(*args) ⇒ Object
656 657 658 |
# File 'lib/formkeeper.rb', line 656 def filters(*args) @default_filters = args end |