Module: Rxhp::AttributeValidator::ClassMethods

Defined in:
lib/rxhp/attribute_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#acceptable_attributesObject

Returns the value of attribute acceptable_attributes.



110
111
112
# File 'lib/rxhp/attribute_validator.rb', line 110

def acceptable_attributes
  @acceptable_attributes
end

#required_attributesObject

Returns the value of attribute required_attributes.



110
111
112
# File 'lib/rxhp/attribute_validator.rb', line 110

def required_attributes
  @required_attributes
end

Instance Method Details

#accept_all_attributesObject

Accept any attributes whatsoever.



142
143
144
# File 'lib/rxhp/attribute_validator.rb', line 142

def accept_all_attributes
  accept_attributes Object
end

#accept_attributes(pattern) ⇒ Object Also known as: accept_attribute

Accept all attributes matching the specified pattern.

Examples:

accept_attribute 'id'
accept_attribute /^data-/
accept_attributes ['href', 'src']
accept_attributes ({ 'type' => ['checkbox', 'text', 'submit'] })

Parameters:

  • pattern

    can be a:

    Symbol

    must equal the attribute name after converting to a String, and replacing underscores with hyphens.

    Object

    must match the attribute name with ===.

    Array

    the members must be a any of the above that matches the attribute name.

    Hash

    the key can be any of the above that matches the attribute name; the value is matched against the attribute value in the same way.



127
128
129
# File 'lib/rxhp/attribute_validator.rb', line 127

def accept_attributes pattern
  acceptable_attributes.push pattern
end

#require_attributes(pattern) ⇒ Object Also known as: require_attribute

Require an attribute matching the specified pattern.

Parameters:



135
136
137
138
# File 'lib/rxhp/attribute_validator.rb', line 135

def require_attributes pattern
  accept_attributes pattern
  required_attributes.push pattern
end