descendants_describable 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/descendants_describable.rb +1 -1
- data/lib/descendants_describable/version.rb +1 -1
- data/spec/descendants_describable_spec.rb +35 -34
- data/spec/spec_helper.rb +0 -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: bc589770060e65c44af39c504e7ae4ce78a92eaa
|
4
|
+
data.tar.gz: 5c25a8058d40a279bdbafa4378a697f0a18ed4ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0943831d705e1e240e410c791a49ea32883f88387ca18279c4b3ea7512c81f83a73307d7fcc424495eb8ceabc251fedde35dcb01d98b052f6a93dc594e184be
|
7
|
+
data.tar.gz: 41e6fc75531d440ce5ee376815c432209fc01076f31c333665a295b9eadf2c5bf985d2abe0a8c010eed716edbb718470bf665862b2b02a9c102608125cdc9197
|
@@ -17,7 +17,7 @@ module DescendantsDescribable
|
|
17
17
|
|
18
18
|
attr_accessor :new_class
|
19
19
|
|
20
|
-
def initialize(parent, description_module, description_proc)
|
20
|
+
def initialize(parent, description_module, description_proc = -> {})
|
21
21
|
@common_modules = []
|
22
22
|
@descendant_names = []
|
23
23
|
@parent = parent
|
@@ -16,44 +16,45 @@ module Models
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
# in your model
|
19
20
|
class Model < ActiveRecord::Base
|
20
21
|
include DescendantsDescribable
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# in config/initializers/#{name_of_model}}.rb
|
25
|
+
Model.describe_descendants_with(Models::Descriptors) do
|
26
|
+
walks_like_a_duck do
|
27
|
+
type :badger
|
28
|
+
type :hadger do
|
29
|
+
is_a_witch
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
floats_like_a_duck do
|
33
|
+
type :tadger
|
34
|
+
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
+
is_a_witch do
|
37
|
+
type :madger
|
36
38
|
end
|
39
|
+
end
|
37
40
|
|
38
|
-
|
39
|
-
|
41
|
+
talks_like_a_duck do
|
42
|
+
type :fadger
|
40
43
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
type :tadger
|
44
|
+
floats_like_a_duck do
|
45
|
+
type :ladger do
|
46
|
+
is_a_witch
|
46
47
|
end
|
48
|
+
type :tadger
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
describe DescendantsDescribable do
|
52
|
-
|
53
54
|
describe '.type - for subclass generation' do
|
54
55
|
it 'creates new subclass of each type' do
|
55
56
|
[Badger, Hadger, Fadger, Ladger, Tadger].each do |klass|
|
56
|
-
expect(klass < Model).to
|
57
|
+
expect(klass < Model).to be_truthy
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -63,19 +64,19 @@ describe DescendantsDescribable do
|
|
63
64
|
it { should respond_to(:is_a_witch) }
|
64
65
|
|
65
66
|
it 'includes module into new class' do
|
66
|
-
expect(Badger < Models::Descriptors::WalksLikeADuck).to
|
67
|
-
expect(Hadger < Models::Descriptors::IsAWitch).to
|
68
|
-
expect(Fadger < Models::Descriptors::TalksLikeADuck).to
|
69
|
-
expect(Ladger < Models::Descriptors::FloatsLikeADuck).to
|
70
|
-
expect(Ladger < Models::Descriptors::TalksLikeADuck).to
|
71
|
-
expect(Ladger < Models::Descriptors::IsAWitch).to
|
72
|
-
|
73
|
-
expect(Tadger < Models::Descriptors::FloatsLikeADuck).to
|
74
|
-
expect(Tadger < Models::Descriptors::WalksLikeADuck).to
|
75
|
-
expect(Tadger < Models::Descriptors::TalksLikeADuck).to
|
76
|
-
|
77
|
-
expect(Madger < Models::Descriptors::WalksLikeADuck).to
|
78
|
-
expect(Madger < Models::Descriptors::IsAWitch).to
|
67
|
+
expect(Badger < Models::Descriptors::WalksLikeADuck).to be_truthy
|
68
|
+
expect(Hadger < Models::Descriptors::IsAWitch).to be_truthy
|
69
|
+
expect(Fadger < Models::Descriptors::TalksLikeADuck).to be_truthy
|
70
|
+
expect(Ladger < Models::Descriptors::FloatsLikeADuck).to be_truthy
|
71
|
+
expect(Ladger < Models::Descriptors::TalksLikeADuck).to be_truthy
|
72
|
+
expect(Ladger < Models::Descriptors::IsAWitch).to be_truthy
|
73
|
+
|
74
|
+
expect(Tadger < Models::Descriptors::FloatsLikeADuck).to be_truthy
|
75
|
+
expect(Tadger < Models::Descriptors::WalksLikeADuck).to be_truthy
|
76
|
+
expect(Tadger < Models::Descriptors::TalksLikeADuck).to be_truthy
|
77
|
+
|
78
|
+
expect(Madger < Models::Descriptors::WalksLikeADuck).to be_truthy
|
79
|
+
expect(Madger < Models::Descriptors::IsAWitch).to be_truthy
|
79
80
|
end
|
80
81
|
end
|
81
82
|
end
|
data/spec/spec_helper.rb
CHANGED