attrio 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attrio.rb +1 -0
- data/lib/attrio/types/set.rb +34 -0
- data/lib/attrio/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a48e9858e6427010ea2fd9a3eed6bbce23ec937
|
4
|
+
data.tar.gz: a12796dd65e3629247a51b3d98934bdf5eda6a8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c39c375f692678255881a6dbd488e9a45cafb931e0a83b745a8fe214a75c5d1d76a62d95efc730af924966998d134990e29469ef43270072c10a99f303cb349f
|
7
|
+
data.tar.gz: 5c403918f66223d3c3d3eddf19379ac115505fcf31b2a5fd69185db2d93d1a6adc9444235c58c3ca07fc722f6668bc1d29d7da68b8ed626edb4e4eb3f225843b
|
data/lib/attrio.rb
CHANGED
@@ -83,6 +83,7 @@ module Attrio
|
|
83
83
|
autoload :DateTime, 'attrio/types/date_time'
|
84
84
|
autoload :Float, 'attrio/types/float'
|
85
85
|
autoload :Integer, 'attrio/types/integer'
|
86
|
+
autoload :Set, 'attrio/types/set'
|
86
87
|
autoload :Symbol, 'attrio/types/symbol'
|
87
88
|
autoload :Time, 'attrio/types/time'
|
88
89
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Attrio
|
4
|
+
module Types
|
5
|
+
class Set < Array
|
6
|
+
def self.typecast(value, options = {})
|
7
|
+
begin
|
8
|
+
set = value.respond_to?(:split) ? value.split(options[:split]).to_set : Attrio::Helpers.to_a(value).to_set
|
9
|
+
|
10
|
+
if options[:element].present?
|
11
|
+
type = Attrio::AttributesParser.cast_type(self.element_type(options[:element]))
|
12
|
+
options = self.element_options(options[:element])
|
13
|
+
|
14
|
+
set.map! do |item|
|
15
|
+
if type.respond_to?(:typecast) && type.respond_to?(:typecasted?)
|
16
|
+
type.typecasted?(item) ? item : type.typecast(item, options)
|
17
|
+
else
|
18
|
+
type == Hash && item.is_a?(Hash) ? value : type.new(item)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
set
|
24
|
+
rescue ArgumentError => e
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.typecasted?(value)
|
30
|
+
value.is_a? ::Set
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/attrio/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attrio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Alexandrov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- lib/attrio/types/date_time.rb
|
134
134
|
- lib/attrio/types/float.rb
|
135
135
|
- lib/attrio/types/integer.rb
|
136
|
+
- lib/attrio/types/set.rb
|
136
137
|
- lib/attrio/types/symbol.rb
|
137
138
|
- lib/attrio/types/time.rb
|
138
139
|
- lib/attrio/version.rb
|
@@ -175,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
176
|
version: '0'
|
176
177
|
requirements: []
|
177
178
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.0.
|
179
|
+
rubygems_version: 2.0.6
|
179
180
|
signing_key:
|
180
181
|
specification_version: 4
|
181
182
|
summary: Attributes for plain old Ruby objects. No dependencies, only simplicity and
|
@@ -201,3 +202,4 @@ test_files:
|
|
201
202
|
- spec/unit/types/integer_spec.rb
|
202
203
|
- spec/unit/types/symbol_spec.rb
|
203
204
|
- spec/unit/types/time_spec.rb
|
205
|
+
has_rdoc:
|