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.



637
638
639
640
641
642
643
# File 'lib/formkeeper.rb', line 637

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



671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/formkeeper.rb', line 671

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.



635
636
637
# File 'lib/formkeeper.rb', line 635

def checkboxes
  @checkboxes
end

#combinationsObject (readonly)

Returns the value of attribute combinations.



635
636
637
# File 'lib/formkeeper.rb', line 635

def combinations
  @combinations
end

#default_filtersObject (readonly)

Returns the value of attribute default_filters.



635
636
637
# File 'lib/formkeeper.rb', line 635

def default_filters
  @default_filters
end

#encoding_filterObject (readonly)

Returns the value of attribute encoding_filter.



635
636
637
# File 'lib/formkeeper.rb', line 635

def encoding_filter
  @encoding_filter
end

#fieldsObject (readonly)

Returns the value of attribute fields.



635
636
637
# File 'lib/formkeeper.rb', line 635

def fields
  @fields
end

Instance Method Details

#combination(name, criteria) ⇒ Object

Raises:

  • (ArgumentError)


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

def combination(name, criteria)
  raise ArgumentError.new unless criteria.kind_of?(Hash)
  @combinations[name.to_sym] = Criteria::Combination.new(criteria)
end

#encoding(code) ⇒ Object



645
646
647
# File 'lib/formkeeper.rb', line 645

def encoding(code)
  @encoding_filter = Filter::ToUTF8.new(code)
end

#field(name, criteria) ⇒ Object

Raises:

  • (ArgumentError)


653
654
655
656
# File 'lib/formkeeper.rb', line 653

def field(name, criteria)
  raise ArgumentError.new unless criteria.kind_of?(Hash)
  @fields[name.to_sym] = Criteria::Field.new(criteria)
end

#filters(*args) ⇒ Object



649
650
651
# File 'lib/formkeeper.rb', line 649

def filters(*args)
  @default_filters = args
end

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

Raises:

  • (ArgumentError)


658
659
660
661
# File 'lib/formkeeper.rb', line 658

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