Module: EasyType::ArrayProperty
- Defined in:
- lib/easy_type/array_property.rb
Overview
Includes all behaviour needed for an Array property
Instance Method Summary collapse
-
#change_to_s(current, should) ⇒ Object
Print a good change message when changing the contents of an array.
- #insync?(is) ⇒ Boolean
- #unsafe_validate(value) ⇒ Object
Instance Method Details
#change_to_s(current, should) ⇒ Object
Print a good change message when changing the contents of an array
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/easy_type/array_property.rb', line 30 def change_to_s(current, should) current = [] if current == :absent should = [] if should == :absent = '' += "removing #{(current - should).join(', ')} " unless (current - should).inspect == '[]' += "adding #{(should - current).join(', ')} " unless (should - current).inspect == '[]' # # If the array contains the same value twice e.g. compare ['Server','Server'], # the current algorithm returns an empty string. In that case we use the full value. # = "changed to #{should}" if .empty? end |
#insync?(is) ⇒ Boolean
17 18 19 20 21 22 23 24 25 |
# File 'lib/easy_type/array_property.rb', line 17 def insync?(is) if is == :absent should.empty? elsif should == :absent is.empty? else is.sort == should.sort end end |
#unsafe_validate(value) ⇒ Object
12 13 14 15 |
# File 'lib/easy_type/array_property.rb', line 12 def unsafe_validate(value) raise 'You need to specify an Array instead of a comma separated string' if value =~ /,/ self.class.coerce(value) if self.class.instance_variable_get(:@data_type) end |