rebase_attr 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -9
- data/README.md +5 -5
- data/lib/rebase_attr/version.rb +1 -1
- data/lib/rebase_attr.rb +4 -0
- data/spec/rebase_attr_spec.rb +39 -8
- 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: 1c989126e78f373d7608f11824429b65974311bc
|
4
|
+
data.tar.gz: 2859dd7b67c93645a72d0ad8f38ee128b9d72d29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e812eced8377afca51ce32ee032411782b1aba3395df1b7480603011a2c6a3e988406d0d12eb6d3fad162afdab3c0353ab7c67e5256e1add033e540b8991afc3
|
7
|
+
data.tar.gz: bc4df6f016698c5a4ec2c89c48eda5f243beb5c709a29f10d65331b80f344076c5e4bd7b523adf335bc44b40b39cb8a40a6d8834524a2adba2a4a537cbf383b4
|
data/.gitignore
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
10
18
|
*.bundle
|
11
19
|
*.so
|
12
20
|
*.o
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# rebase_attr [![Gem Version](https://badge.fury.io/rb/
|
1
|
+
# rebase_attr [![Gem Version](https://badge.fury.io/rb/rebase_attr.svg)](http://badge.fury.io/rb/rebase_attr)
|
2
2
|
|
3
3
|
Convert an attribute to a specified base.
|
4
4
|
|
@@ -59,13 +59,13 @@ Other functions you get when using rebase_attr:
|
|
59
59
|
bill.id_without_rebase = 3151957185711
|
60
60
|
bill.id
|
61
61
|
=> "2rnfkjw5f"
|
62
|
-
Bill.find(Bill.
|
62
|
+
Bill.find(Bill.decode_id("2rnfkjw5f"))
|
63
63
|
=> #<Bill id: 3151957185711>
|
64
|
-
bill.
|
64
|
+
bill.decode_id("2rnfkjw5f")
|
65
65
|
=> 3151957185711
|
66
|
-
Bill.
|
66
|
+
Bill.encode_id(3151957185711)
|
67
67
|
=> "2rnfkjw5f"
|
68
|
-
bill.
|
68
|
+
bill.encode_id(3151957185711)
|
69
69
|
=> "2rnfkjw5f"
|
70
70
|
```
|
71
71
|
|
data/lib/rebase_attr/version.rb
CHANGED
data/lib/rebase_attr.rb
CHANGED
@@ -12,6 +12,8 @@ module RebaseAttr
|
|
12
12
|
attributes.each do |attr|
|
13
13
|
# encoders & decoders
|
14
14
|
define_singleton_method :"encode_#{attr}" do |decoded|
|
15
|
+
break nil if decoded.nil?
|
16
|
+
|
15
17
|
result = decoded
|
16
18
|
raise TypeError, "decoded value must implement #to_i, #{result.inspect} given" unless result.respond_to?(:to_i)
|
17
19
|
result = result.to_i(from || 10) if result.is_a?(String)
|
@@ -25,6 +27,8 @@ module RebaseAttr
|
|
25
27
|
end
|
26
28
|
|
27
29
|
define_singleton_method :"decode_#{attr}" do |encoded|
|
30
|
+
break nil if encoded.nil?
|
31
|
+
|
28
32
|
result = encoded
|
29
33
|
if deconvert
|
30
34
|
begin
|
data/spec/rebase_attr_spec.rb
CHANGED
@@ -17,31 +17,62 @@ describe RebaseAttr::Generator do
|
|
17
17
|
describe "#encode" do
|
18
18
|
specify { expect(klass.encode_x(decoded)).to eq(encoded) }
|
19
19
|
specify { expect(instance.encode_x(decoded)).to eq(encoded) }
|
20
|
+
specify { expect(instance.encode_x(nil)).to be_nil }
|
20
21
|
end
|
21
22
|
|
22
23
|
describe "#decode" do
|
23
24
|
specify { expect(klass.decode_x(encoded)).to eq(decoded) }
|
25
|
+
specify { expect(klass.decode_x(nil)).to be_nil }
|
24
26
|
specify { expect(instance.decode_x(encoded)).to eq(decoded) }
|
27
|
+
specify { expect(instance.decode_x(nil)).to be_nil }
|
25
28
|
end
|
26
29
|
|
27
30
|
describe "reader" do
|
28
|
-
|
29
|
-
|
31
|
+
context "when not nil" do
|
32
|
+
before { d = decoded; instance.instance_eval { @x = d } } # converting decoded to local variable so I can use it inside instance_eval
|
33
|
+
its(:x) { should == encoded }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when nil" do
|
37
|
+
before { instance.instance_eval { @x = nil } } # converting decoded to local variable so I can use it inside instance_eval
|
38
|
+
its(:x) { should be_nil }
|
39
|
+
end
|
30
40
|
end
|
31
41
|
|
32
42
|
describe "#without_rebase" do
|
33
|
-
|
34
|
-
|
43
|
+
context "when not nil" do
|
44
|
+
before { d = decoded; instance.instance_eval { @x = d } } # converting decoded to local variable so I can use it inside instance_eval
|
45
|
+
its(:x_without_rebase) { should == decoded }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when nil" do
|
49
|
+
before { instance.instance_eval { @x = nil } } # converting decoded to local variable so I can use it inside instance_eval
|
50
|
+
its(:x_without_rebase) { should be_nil }
|
51
|
+
end
|
35
52
|
end
|
36
53
|
|
37
54
|
describe "writer" do
|
38
|
-
|
39
|
-
|
55
|
+
context "when not nil" do
|
56
|
+
before { instance.x = encoded }
|
57
|
+
specify { expect(instance.instance_eval { @x }).to eq(decoded) }
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when nil" do
|
61
|
+
before { instance.x = nil }
|
62
|
+
specify { expect(instance.instance_eval { @x }).to be_nil }
|
63
|
+
end
|
40
64
|
end
|
41
65
|
|
42
66
|
describe "#without_rebase=" do
|
43
|
-
|
44
|
-
|
67
|
+
context "when not nil" do
|
68
|
+
before { instance.x_without_rebase = decoded }
|
69
|
+
specify { expect(instance.instance_eval { @x }).to eq(decoded) }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when nil" do
|
73
|
+
before { instance.x_without_rebase = nil }
|
74
|
+
specify { expect(instance.instance_eval { @x }).to be_nil }
|
75
|
+
end
|
45
76
|
end
|
46
77
|
end
|
47
78
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rebase_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oded Niv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|