Class: Attrio::Types::Set
Class Method Summary
collapse
Methods inherited from Base
default_reader_aliases, default_writer_aliases
Class Method Details
.typecast(value, options = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/attrio/types/set.rb', line 6
def self.typecast(value, options = {})
begin
set = value.respond_to?(:split) ? value.split(options[:split]).to_set : Attrio::Helpers.to_a(value).to_set
if options[:element].present?
type = Attrio::AttributesParser.cast_type(self.element_type(options[:element]))
options = self.element_options(options[:element])
set.map! do |item|
if type.respond_to?(:typecast) && type.respond_to?(:typecasted?)
type.typecasted?(item) ? item : type.typecast(item, options)
else
type == Hash && item.is_a?(Hash) ? value : type.new(item)
end
end
end
set
rescue ArgumentError => e
nil
end
end
|
.typecasted?(value, options = {}) ⇒ Boolean
29
30
31
|
# File 'lib/attrio/types/set.rb', line 29
def self.typecasted?(value, options = {})
value.is_a? ::Set
end
|