acts_as_duration 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/acts_as_duration/base.rb +9 -7
- data/lib/acts_as_duration/version.rb +1 -1
- data/test/acts_as_duration_test.rb +15 -0
- data/test/dummy/log/test.log +58 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d548368dd2f852f56c9d78f6551fd9fe4e1f76
|
4
|
+
data.tar.gz: 3a89a824fd3ed56c3c64d6a9ceffcf2cb96f4aba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87af822b4eec97f6b82922cd8b502a0ce1bc278a8997aea46a641ffeb54464d7441ceda95b553bdaa2a7ac798b947129101c4d4955fab1303c33fb71a9a47010
|
7
|
+
data.tar.gz: b7b5d91827ae60df31fdf294f187a7dd252de2828de535727273344bc703e412976387b87d29e25e1661190ff0301d750f768259f5616825424569b3c0b7ad71
|
@@ -7,15 +7,17 @@ module ActsAsDuration
|
|
7
7
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
-
def acts_as_duration(
|
10
|
+
def acts_as_duration(*base_attrs, **options)
|
11
11
|
valid_units = [:seconds, :minutes, :hours, :days]
|
12
|
-
|
12
|
+
base_attrs.each do |base_attr|
|
13
|
+
base_unit = options[:attr_unit] || base_attr[/(#{valid_units.join('|')})/,1].to_sym
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
(valid_units - [base_unit]).each do |new_unit|
|
16
|
+
name = base_attr.to_s.gsub!(base_unit.to_s, new_unit.to_s)
|
17
|
+
options_hash = {name: name, base_attr: base_attr, base_unit: base_unit, new_unit: new_unit}
|
18
|
+
define_reader_method(options_hash)
|
19
|
+
define_writer_method(options_hash) unless options[:read_only]
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -49,4 +49,19 @@ class ActsAsDurationTest < ActiveSupport::TestCase
|
|
49
49
|
assert_equal 2.03, foo.barfoo_hours
|
50
50
|
end
|
51
51
|
|
52
|
+
test 'accepts multiple attributs as well as hash arguments' do
|
53
|
+
Foobar.class_eval do
|
54
|
+
attr_accessor :a_seconds, :b_minutes, :c_hours
|
55
|
+
acts_as_duration :a_seconds, :b_minutes, :c_hours, read_only: true
|
56
|
+
end
|
57
|
+
|
58
|
+
expected_methods = [:a_minutes, :a_hours, :b_seconds, :b_hours, :c_seconds, :c_minutes]
|
59
|
+
assert (expected_methods - Foobar.instance_methods).empty?
|
60
|
+
|
61
|
+
unexpected_methods = [:a_minutes=, :a_hours=, :b_seconds=, :b_hours=, :c_seconds=, :c_minutes=]
|
62
|
+
assert_equal 6, (unexpected_methods - Foobar.instance_methods).count
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
|
52
67
|
end
|
data/test/dummy/log/test.log
CHANGED
@@ -846,3 +846,61 @@ ActsAsDurationTest: test_converts_from_seconds_to_minutes,_hours_and_saves
|
|
846
846
|
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
847
847
|
[1m[36mFoobar Load (0.2ms)[0m [1mSELECT "foobars".* FROM "foobars" WHERE "foobars"."id" = ? LIMIT 1[0m [["id", 1]]
|
848
848
|
[1m[35m (0.6ms)[0m rollback transaction
|
849
|
+
[1m[36m (0.7ms)[0m [1mbegin transaction[0m
|
850
|
+
-----------------------------------------------------------------------------
|
851
|
+
ActsAsDurationTest: test_accepts_multiple_attributs_as_well_as_hash_arguments
|
852
|
+
-----------------------------------------------------------------------------
|
853
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
854
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
855
|
+
--------------------------------------------------------------------
|
856
|
+
ActsAsDurationTest: test_adds_additional_conversion_methods_to_model
|
857
|
+
--------------------------------------------------------------------
|
858
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
859
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
860
|
+
---------------------------------------------------------
|
861
|
+
ActsAsDurationTest: test_adds_conversion_methods_to_model
|
862
|
+
---------------------------------------------------------
|
863
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
864
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
865
|
+
-------------------------------------------------------------------
|
866
|
+
ActsAsDurationTest: test_converts_from_minutes_to_seconds_and_hours
|
867
|
+
-------------------------------------------------------------------
|
868
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
869
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
870
|
+
--------------------------------------------------------------------------
|
871
|
+
ActsAsDurationTest: test_converts_from_seconds_to_minutes,_hours_and_saves
|
872
|
+
--------------------------------------------------------------------------
|
873
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
874
|
+
[1m[36mSQL (37.2ms)[0m [1mINSERT INTO "foobars" ("created_at", "test_seconds", "updated_at") VALUES (?, ?, ?)[0m [["created_at", Fri, 25 Apr 2014 17:17:26 UTC +00:00], ["test_seconds", 7380], ["updated_at", Fri, 25 Apr 2014 17:17:26 UTC +00:00]]
|
875
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
876
|
+
[1m[36mFoobar Load (0.2ms)[0m [1mSELECT "foobars".* FROM "foobars" WHERE "foobars"."id" = ? LIMIT 1[0m [["id", 1]]
|
877
|
+
[1m[35m (0.6ms)[0m rollback transaction
|
878
|
+
[1m[36m (0.4ms)[0m [1mbegin transaction[0m
|
879
|
+
-----------------------------------------------------------------------------
|
880
|
+
ActsAsDurationTest: test_accepts_multiple_attributs_as_well_as_hash_arguments
|
881
|
+
-----------------------------------------------------------------------------
|
882
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
883
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
884
|
+
--------------------------------------------------------------------
|
885
|
+
ActsAsDurationTest: test_adds_additional_conversion_methods_to_model
|
886
|
+
--------------------------------------------------------------------
|
887
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
888
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
889
|
+
---------------------------------------------------------
|
890
|
+
ActsAsDurationTest: test_adds_conversion_methods_to_model
|
891
|
+
---------------------------------------------------------
|
892
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
893
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
894
|
+
-------------------------------------------------------------------
|
895
|
+
ActsAsDurationTest: test_converts_from_minutes_to_seconds_and_hours
|
896
|
+
-------------------------------------------------------------------
|
897
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
898
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
899
|
+
--------------------------------------------------------------------------
|
900
|
+
ActsAsDurationTest: test_converts_from_seconds_to_minutes,_hours_and_saves
|
901
|
+
--------------------------------------------------------------------------
|
902
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
903
|
+
[1m[36mSQL (2.6ms)[0m [1mINSERT INTO "foobars" ("created_at", "test_seconds", "updated_at") VALUES (?, ?, ?)[0m [["created_at", Fri, 25 Apr 2014 17:17:57 UTC +00:00], ["test_seconds", 7380], ["updated_at", Fri, 25 Apr 2014 17:17:57 UTC +00:00]]
|
904
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
905
|
+
[1m[36mFoobar Load (0.1ms)[0m [1mSELECT "foobars".* FROM "foobars" WHERE "foobars"."id" = ? LIMIT 1[0m [["id", 1]]
|
906
|
+
[1m[35m (0.7ms)[0m rollback transaction
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_duration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yonah Forst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|