attributable 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attributable.rb +2 -2
- data/lib/attributable/version.rb +1 -1
- data/spec/attributable/specialisation_spec.rb +15 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c22dc4806f8e50155cb39df375de2e883edfb086
|
4
|
+
data.tar.gz: 5edda9c0de87966920404d14b07a8ca78e395657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b50d6942f2276f8571991bb33470191cceb7a215bc78d0e5318466249bba357c443a3e244db843b09ae8a582fdade35e03492666f29eecd1eccc43ebb4f02e77
|
7
|
+
data.tar.gz: ee3fad3f3cffafc5fe94d0ef27c56c590e06cbbcc8708f73aa51fe1e0a429b2179b471a3cea5259df251428d45003265476c2e13abc800f5019f477e6be724c0
|
data/lib/attributable.rb
CHANGED
@@ -16,7 +16,6 @@ module Attributable
|
|
16
16
|
@predefined_attributes ||= {}
|
17
17
|
@predefined_attributes = super_attributes.merge(@predefined_attributes)
|
18
18
|
add_instance_methods(@predefined_attributes)
|
19
|
-
@predefined_attributes
|
20
19
|
end
|
21
20
|
|
22
21
|
private
|
@@ -44,7 +43,8 @@ module Attributable
|
|
44
43
|
|
45
44
|
define_method "initialize_attributes" do |attributes = {}|
|
46
45
|
if self.class.superclass.kind_of? Attributable
|
47
|
-
|
46
|
+
super_attributes = self.class.superclass.new.instance_variable_get(:@attributes)
|
47
|
+
predefined_attributes = super_attributes.merge(predefined_attributes)
|
48
48
|
end
|
49
49
|
@attributes = predefined_attributes.merge(attributes)
|
50
50
|
end
|
data/lib/attributable/version.rb
CHANGED
@@ -95,17 +95,30 @@ describe Attributable do
|
|
95
95
|
expect(s.active).to be_false
|
96
96
|
end
|
97
97
|
|
98
|
+
it "should not override any custom methods" do
|
99
|
+
class SuperUser7 < User
|
100
|
+
def inspect
|
101
|
+
"SUPERUSER"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
s = SuperUser7.new(id: 1)
|
106
|
+
|
107
|
+
expect(s.id).to eq(1)
|
108
|
+
expect(s.inspect).to eq("SUPERUSER")
|
109
|
+
end
|
110
|
+
|
98
111
|
it "shouldn't automatically specialise unless superclass is an instance of Attributable" do
|
99
112
|
class PORO
|
100
113
|
attr_accessor :name
|
101
114
|
end
|
102
115
|
|
103
|
-
class
|
116
|
+
class SuperUser8 < PORO
|
104
117
|
extend Attributable
|
105
118
|
attributes :forename, :surname
|
106
119
|
end
|
107
120
|
|
108
|
-
expect {
|
121
|
+
expect { SuperUser8.new }.to_not raise_error
|
109
122
|
end
|
110
123
|
end
|
111
124
|
end
|