aduki 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/aduki.rb +43 -14
- data/lib/aduki/version.rb +1 -1
- metadata +13 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ca8a03939e3f4904afebba8a335ca2f7e3fdcc5
|
4
|
+
data.tar.gz: 70223137072e357aa6963fa97b3536fe14ffa93d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7bde6768466c7cecde67f17caa5dfa0cd3c4b6956342e75affc73a4447335e6bbc4bf48dd72229456db8926bec4d900c49e297ad9a904088f082303ed8ebf1d5
|
7
|
+
data.tar.gz: 93dab1a3ebcb754f76edc823caea987cdabee8f1d70f24567ca2d2d3c72f91b70ec9a64cf415805fc341d94094d12360761dc83633a5f7f69119a0da1c92063c
|
data/lib/aduki.rb
CHANGED
@@ -29,6 +29,11 @@ module Aduki
|
|
29
29
|
collector
|
30
30
|
end
|
31
31
|
|
32
|
+
def self.maybe_parse_date str
|
33
|
+
return nil if (str == nil) || (str == '')
|
34
|
+
Date.parse(str)
|
35
|
+
end
|
36
|
+
|
32
37
|
def self.to_value klass, setter, value
|
33
38
|
return value.map { |v| to_value klass, setter, v} if value.is_a? Array
|
34
39
|
|
@@ -36,9 +41,15 @@ module Aduki
|
|
36
41
|
if type.is_a? Hash
|
37
42
|
to_typed_hash type.values.first, value
|
38
43
|
elsif type == Date
|
39
|
-
|
44
|
+
case value
|
45
|
+
when Date; value
|
46
|
+
when String; maybe_parse_date(value)
|
47
|
+
end
|
40
48
|
elsif type == Time
|
41
|
-
|
49
|
+
case value
|
50
|
+
when Time; value
|
51
|
+
when String; Time.parse(value)
|
52
|
+
end
|
42
53
|
elsif type && (type <= Integer)
|
43
54
|
value.to_i
|
44
55
|
elsif type && (type <= Float)
|
@@ -73,22 +84,40 @@ module Aduki
|
|
73
84
|
setters
|
74
85
|
end
|
75
86
|
|
87
|
+
def self.apply_array_attribute klass, object, getter, value
|
88
|
+
setter_method = "#{getter}=".to_sym
|
89
|
+
return unless object.respond_to? setter_method
|
90
|
+
|
91
|
+
array = object.send getter
|
92
|
+
if array == nil
|
93
|
+
array = []
|
94
|
+
object.send(setter_method, array)
|
95
|
+
end
|
96
|
+
array << to_value(klass, getter, value)
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.apply_single_attribute klass, object, setter, value
|
100
|
+
setter_method = "#{setter}=".to_sym
|
101
|
+
return unless object.respond_to? setter_method
|
102
|
+
|
103
|
+
object.send setter_method, to_value(klass, setter, value)
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.apply_attribute klass, object, setter, value
|
107
|
+
if setter.match(/\[\d+\]/)
|
108
|
+
getter = setter.gsub(/\[\d+\]/, '').to_sym
|
109
|
+
apply_array_attribute klass, object, getter, value
|
110
|
+
else
|
111
|
+
apply_single_attribute klass, object, setter, value
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
76
115
|
def self.apply_attributes object, attrs
|
77
|
-
setters = split_attributes
|
116
|
+
setters = split_attributes(attrs || { })
|
78
117
|
klass = object.class
|
79
118
|
|
80
119
|
setters.sort.each do |setter, value|
|
81
|
-
|
82
|
-
setter = setter.gsub(/\[\d+\]/, '')
|
83
|
-
array = object.send setter.to_sym
|
84
|
-
if array == nil
|
85
|
-
array = []
|
86
|
-
object.send("#{setter}=", array)
|
87
|
-
end
|
88
|
-
array << to_value(klass, setter, value)
|
89
|
-
else
|
90
|
-
object.send "#{setter}=", to_value(klass, setter, value)
|
91
|
-
end
|
120
|
+
apply_attribute klass, object, setter, value
|
92
121
|
end
|
93
122
|
end
|
94
123
|
|
data/lib/aduki/version.rb
CHANGED
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aduki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.11
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Conan Dalton
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '2.9'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '2.9'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec_numbering_formatter
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: recursive attribute setting for ruby objects
|
@@ -50,8 +45,8 @@ executables: []
|
|
50
45
|
extensions: []
|
51
46
|
extra_rdoc_files: []
|
52
47
|
files:
|
53
|
-
- .gitignore
|
54
|
-
- .rspec
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
55
50
|
- Gemfile
|
56
51
|
- LICENSE.txt
|
57
52
|
- README.md
|
@@ -71,27 +66,26 @@ files:
|
|
71
66
|
homepage: https://github.com/conanite/aduki
|
72
67
|
licenses:
|
73
68
|
- MIT
|
69
|
+
metadata: {}
|
74
70
|
post_install_message:
|
75
71
|
rdoc_options: []
|
76
72
|
require_paths:
|
77
73
|
- lib
|
78
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
75
|
requirements:
|
81
|
-
- -
|
76
|
+
- - ">="
|
82
77
|
- !ruby/object:Gem::Version
|
83
78
|
version: '0'
|
84
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
80
|
requirements:
|
87
|
-
- -
|
81
|
+
- - ">="
|
88
82
|
- !ruby/object:Gem::Version
|
89
83
|
version: '0'
|
90
84
|
requirements: []
|
91
85
|
rubyforge_project:
|
92
|
-
rubygems_version:
|
86
|
+
rubygems_version: 2.2.2
|
93
87
|
signing_key:
|
94
|
-
specification_version:
|
88
|
+
specification_version: 4
|
95
89
|
summary: set object attributes recursively from an attributes hash
|
96
90
|
test_files:
|
97
91
|
- spec/array_attribute_spec.rb
|