module Crabfarm::Assertion::Fields::ClassMethods
Public Instance Methods
field_defaults()
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 59 def field_defaults @field_defaults ||= {} end
fields()
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 55 def fields @fields ||= [] end
has_array(_name)
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 31 def has_array(_name) has_field(_name, field_default: [], field_readonly: true) end
has_asserted_field(_name, _assertion, _options={})
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 27 def has_asserted_field(_name, _assertion, _options={}) has_field(_name, _options.merge(field_assertion: _assertion)) end
has_boolean(_name, _options={})
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 51 def has_boolean(_name, _options={}) has_asserted_field _name, :is_boolean, _options end
has_field(_name, _options={})
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 11 def has_field(_name, _options={}) name = _name.to_sym fields << name field_defaults[name] = _options.delete :field_default assertion = _options.delete :field_assertion if assertion define_method("#{name}=") { |v| field_hash[name] = assert(v).send(assertion, _options) } elsif not _options[:field_readonly] define_method("#{name}=") { |v| field_hash[name] = v } end define_method(name) { field_hash[name] } end
has_float(_name, _options={})
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 39 def has_float(_name, _options={}) has_asserted_field _name, :is_float, _options end
has_integer(_name, _options={})
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 35 def has_integer(_name, _options={}) has_asserted_field _name, :is_integer, _options end
has_string(_name, _options={})
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 43 def has_string(_name, _options={}) has_asserted_field _name, :is_string, _options end
has_word(_name, _options={})
click to toggle source
# File lib/crabfarm/assertion/fields.rb, line 47 def has_word(_name, _options={}) has_asserted_field _name, :is_word, _options end