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.



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

#checkboxesObject (readonly)

Returns the value of attribute checkboxes.



630
631
632
# File 'lib/formkeeper.rb', line 630

def checkboxes
  @checkboxes
end

#combinationsObject (readonly)

Returns the value of attribute combinations.



630
631
632
# File 'lib/formkeeper.rb', line 630

def combinations
  @combinations
end

#default_filtersObject (readonly)

Returns the value of attribute default_filters.



630
631
632
# File 'lib/formkeeper.rb', line 630

def default_filters
  @default_filters
end

#encoding_filterObject (readonly)

Returns the value of attribute encoding_filter.



630
631
632
# File 'lib/formkeeper.rb', line 630

def encoding_filter
  @encoding_filter
end

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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

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

Raises:

  • (ArgumentError)


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

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