multiparameter_attributes_handler 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.rdoc +5 -2
- data/lib/multiparameter_attributes_handler/manipulator.rb +5 -1
- data/lib/multiparameter_attributes_handler/version.rb +12 -3
- data/test/multiparameter_attributes_handler/manipulator_test.rb +10 -3
- data/test/multiparameter_attributes_handler_test.rb +2 -2
- data/test/thing_test.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTE5NGNhNTY0NmE4NzY2MzVmOGM5ZmUyZjM3YzI2MTI4N2U1M2EzNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGM1NDgzMzZmN2RjNTRiYTYyOWVhMzI0NzM4YWMyYWYxMjAyMmVhMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGE5NGRlNzMyNWIxZTIxMjYwYTA5MmUwN2Y3Y2JmM2UxN2EzNjA5NTVlMWJm
|
10
|
+
NjJhYTZmYmFmNjQxNDlmNTJkMDJlMjQ1NGYwOGExZDJmZGM1MmUzMjhkMmRi
|
11
|
+
YzdmYmViODRhNjIzYzVlYmIzMmNjOWUwZGVhMTAwNGY2MTM1YjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTcxNTlmYmYxMjk3OWRmYmJjMTQxYzcxN2FmYWM3ZTVlYzMyZDg4MzI0NzU2
|
14
|
+
NGM0ZTg4M2U1ZTliNWNkZTBlZTAwMGM3OTcyMTY2NmZhNDg2MmRhNDhmYTk1
|
15
|
+
NTcxN2U2MzExMWQzZTlmMjI2MjA4NDYzMjJiOWYyYmEwMzlkNmY=
|
data/README.rdoc
CHANGED
@@ -32,9 +32,12 @@ This creates a last_read key with a time object derived from the values
|
|
32
32
|
"last_read(1i)" => "2004",
|
33
33
|
"last_read(2i)" => "6",
|
34
34
|
"last_read(3i)" => "24",
|
35
|
-
"last_read" =>
|
35
|
+
"last_read" => Date.new(2004, 6, 24)
|
36
36
|
}
|
37
37
|
|
38
|
+
Note that if hours and minutes are also present, the derived value will be a
|
39
|
+
Time object.
|
40
|
+
|
38
41
|
=== Modifying the output
|
39
42
|
|
40
43
|
If you need to modify the derived values, pass a block to manipulate_all, and
|
@@ -48,7 +51,7 @@ Will create
|
|
48
51
|
"last_read(1i)" => "2004",
|
49
52
|
"last_read(2i)" => "6",
|
50
53
|
"last_read(3i)" => "24",
|
51
|
-
"last_read" =>
|
54
|
+
"last_read" => Date.new('2004', '6', '24').to_s
|
52
55
|
}
|
53
56
|
|
54
57
|
== An ActiveResource example
|
@@ -45,7 +45,11 @@ module MultiparameterAttributesHandler
|
|
45
45
|
private
|
46
46
|
def convert_to_time(multiparameter, values)
|
47
47
|
begin
|
48
|
-
|
48
|
+
if values.length == 3
|
49
|
+
Date.new *values.collect(&:to_i)
|
50
|
+
else
|
51
|
+
Time.local *values
|
52
|
+
end
|
49
53
|
rescue => e
|
50
54
|
msg = "Error determining value_of #{multiparameter} from #{values} (#{e.message})"
|
51
55
|
raise_assignment_errors(multiparameter, values, msg, e)
|
@@ -1,11 +1,20 @@
|
|
1
1
|
module MultiparameterAttributesHandler
|
2
|
-
VERSION = "0.1.
|
2
|
+
VERSION = "0.1.1"
|
3
3
|
end
|
4
4
|
|
5
5
|
# History
|
6
6
|
# =======
|
7
|
-
#
|
8
|
-
# 0.1.
|
7
|
+
#
|
8
|
+
# 0.1.1: Returns Date object if only multiparameter only has three elements
|
9
|
+
# -------------------------------------------------------------------------
|
10
|
+
#
|
11
|
+
# A problem was identified where summer time caused a problem with hour offsets
|
12
|
+
# if the multiparameter was for a date.
|
13
|
+
#
|
14
|
+
# The new logic is that if date and time are contained in the multiparameter,
|
15
|
+
# a Time object is returned. If only date is present, a date object is returned
|
16
|
+
#
|
17
|
+
# 0.1.0: Allowes a block to be user to modify the output
|
9
18
|
# ------------------------------------------------------
|
10
19
|
# A use case was found where the resulting data needed to be stored as a
|
11
20
|
# string, rather than a date. As there may be other ways the output needs
|
@@ -23,18 +23,21 @@ module MultiparameterAttributesHandler
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_value_of_multiparameter
|
26
|
-
assert_equal time_for('last_read'), manipulator.value_of('last_read')
|
27
26
|
assert_equal time_for('other'), manipulator.value_of('other')
|
28
27
|
end
|
29
28
|
|
30
29
|
def test_value_mod_changes_values
|
31
30
|
manipulator = Manipulator.new(hash, &:to_s)
|
32
|
-
assert_equal
|
31
|
+
assert_equal date_for('last_read').to_s, manipulator.value_of('last_read')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_value_of_multiparameter_when_date
|
35
|
+
assert_equal date_for('last_read'), @manipulator.value_of('last_read')
|
33
36
|
end
|
34
37
|
|
35
38
|
def test_value_mod_with_lambda
|
36
39
|
manipulator = Manipulator.new(hash) {|value| value + 1}
|
37
|
-
assert_equal (
|
40
|
+
assert_equal (date_for('last_read') + 1), manipulator.value_of('last_read')
|
38
41
|
end
|
39
42
|
|
40
43
|
def test_output_returns_original_content
|
@@ -108,5 +111,9 @@ module MultiparameterAttributesHandler
|
|
108
111
|
Time.local *manipulator.values_for(field)
|
109
112
|
end
|
110
113
|
|
114
|
+
def date_for(field)
|
115
|
+
Date.new *manipulator.values_for(field).collect(&:to_i)
|
116
|
+
end
|
117
|
+
|
111
118
|
end
|
112
119
|
end
|
@@ -9,12 +9,12 @@ class MultiparameterAttributesHandlerTest < Test::Unit::TestCase
|
|
9
9
|
|
10
10
|
def test_manipulate_all
|
11
11
|
output = MultiparameterAttributesHandler.manipulate_all(attributes)
|
12
|
-
assert_equal
|
12
|
+
assert_equal Date.new(2004, 6, 24), output['last_read']
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_manipulate_all_with_block
|
16
16
|
output = MultiparameterAttributesHandler.manipulate_all(attributes, &:to_s)
|
17
|
-
assert_equal
|
17
|
+
assert_equal Date.new(2004, 6, 24).to_s, output['last_read']
|
18
18
|
end
|
19
19
|
|
20
20
|
def attributes
|
data/test/thing_test.rb
CHANGED
@@ -15,7 +15,7 @@ class ThingTest < Test::Unit::TestCase
|
|
15
15
|
@thing.attributes = attributes
|
16
16
|
# note that extra #to_date call allows test to pass for Oracle, which
|
17
17
|
# treats dates/times the same
|
18
|
-
assert_equal
|
18
|
+
assert_equal Date.new(2004, 6, 24), @thing.attributes['last_read']
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_multiparameter_attributes_on_date_with_empty_year
|
metadata
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiparameter_attributes_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Nichols
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rails forms helpers for date and time fields generate multiparameter
|
14
|
-
params. multiparameter_attributes_handler allows objects to
|
15
|
-
attributes,
|
14
|
+
params. multiparameter_attributes_handler allows objects to use these params.
|
16
15
|
email:
|
17
16
|
- rob@undervale.co.uk
|
18
17
|
executables: []
|
@@ -32,7 +31,8 @@ files:
|
|
32
31
|
- test/thing.rb
|
33
32
|
- test/thing_test.rb
|
34
33
|
homepage: https://github.com/reggieb/multiparameter_attributes_handler
|
35
|
-
licenses:
|
34
|
+
licenses:
|
35
|
+
- MIT-LICENSE
|
36
36
|
metadata: {}
|
37
37
|
post_install_message:
|
38
38
|
rdoc_options: []
|
@@ -50,13 +50,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
version: '0'
|
51
51
|
requirements: []
|
52
52
|
rubyforge_project:
|
53
|
-
rubygems_version: 2.4.
|
53
|
+
rubygems_version: 2.4.1
|
54
54
|
signing_key:
|
55
55
|
specification_version: 4
|
56
|
-
summary: Allows objects
|
56
|
+
summary: Allows non-active_record objects to handle multiparameter params
|
57
57
|
test_files:
|
58
|
-
- test/thing_test.rb
|
59
58
|
- test/multiparameter_attributes_handler_test.rb
|
60
59
|
- test/thing.rb
|
61
60
|
- test/multiparameter_attributes_handler/multiparameter_attributes_handler_error_test.rb
|
62
61
|
- test/multiparameter_attributes_handler/manipulator_test.rb
|
62
|
+
- test/thing_test.rb
|