Class: FormKeeper::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/formkeeper.rb

Defined Under Namespace

Modules: Criteria

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRule

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

#checkboxesObject (readonly)

Returns the value of attribute checkboxes.



642
643
644
# File 'lib/formkeeper.rb', line 642

def checkboxes
  @checkboxes
end

#combinationsObject (readonly)

Returns the value of attribute combinations.



642
643
644
# File 'lib/formkeeper.rb', line 642

def combinations
  @combinations
end

#default_filtersObject (readonly)

Returns the value of attribute default_filters.



642
643
644
# File 'lib/formkeeper.rb', line 642

def default_filters
  @default_filters
end

#encoding_filterObject (readonly)

Returns the value of attribute encoding_filter.



642
643
644
# File 'lib/formkeeper.rb', line 642

def encoding_filter
  @encoding_filter
end

#fieldsObject (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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

#selection(name, criteria) ⇒ Object Also known as: checkbox

Raises:

  • (ArgumentError)


665
666
667
668
# File 'lib/formkeeper.rb', line 665

def selection(name, criteria)
  raise ArgumentError.new unless criteria.kind_of?(Hash)
  @checkboxes[name.to_sym] = Criteria::Checkbox.new(criteria)
end