can_be 0.2.0 → 0.2.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.
- data/CHANGELOG.md +4 -0
- data/README.md +11 -6
- data/lib/can_be/config.rb +2 -3
- data/lib/can_be/model_extensions.rb +4 -3
- data/lib/can_be/processor/instance.rb +1 -1
- data/lib/can_be/version.rb +1 -1
- data/spec/can_be/config_spec.rb +5 -5
- data/spec/support/models.rb +6 -3
- metadata +1 -1
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -75,19 +75,24 @@ end
|
|
75
75
|
|
76
76
|
### Details Model Configuration
|
77
77
|
|
78
|
-
In order to wire up a model to be a CanBe details model, you will need
|
79
|
-
to call the `can_be_detail` method on that model.
|
78
|
+
In order to wire up a model to be a CanBe details model, you will need to call the `can_be_detail` method on that model.
|
80
79
|
|
81
80
|
```ruby
|
82
81
|
class HomeAddressDetail < ActiveRecord::Base
|
83
|
-
can_be_detail :address
|
82
|
+
can_be_detail :address
|
84
83
|
end
|
85
84
|
```
|
86
|
-
The `can_be_detail` method take in
|
85
|
+
The `can_be_detail` method take in one parameter. The parameter is the link to the CanBe model. This must be a symbol that will reference the CanBe model. In order to create the proper symbol, you can execute the following into your Rails console: `<ModelName>.name.underscore.to_sym`. Here is an example: `Address.name.underscore.to_sym`. In the above example, this will be used for the `Address` CanBe model.
|
87
86
|
|
88
|
-
|
87
|
+
You will also need to call the `add_details_model` method in the `can_be` block, passing in the CanBe type and a symbol that represets the details model class.
|
89
88
|
|
90
|
-
|
89
|
+
```ruby
|
90
|
+
class Address < ActiveRecord::Base
|
91
|
+
can_be :home_address, :work_address, :vacation_address do
|
92
|
+
add_details_model :home_address, :home_address_detail
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
91
96
|
|
92
97
|
## Usage
|
93
98
|
|
data/lib/can_be/config.rb
CHANGED
@@ -25,9 +25,8 @@ module CanBe
|
|
25
25
|
@details ||= {}
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
30
|
-
config.details[can_be_type] = klass.name
|
28
|
+
def add_details_model(can_be_type, model_symbol)
|
29
|
+
self.details[can_be_type] = model_symbol
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -9,7 +9,7 @@ module CanBe
|
|
9
9
|
@can_be_config ||= CanBe::Config.new
|
10
10
|
end
|
11
11
|
|
12
|
-
def can_be(*types)
|
12
|
+
def can_be(*types, &block)
|
13
13
|
if types.last.is_a?(Hash)
|
14
14
|
options = types.last
|
15
15
|
types.delete types.last
|
@@ -18,11 +18,12 @@ module CanBe
|
|
18
18
|
can_be_config.types = types
|
19
19
|
can_be_config.parse_options options if options
|
20
20
|
|
21
|
+
can_be_config.instance_eval(&block)if block_given?
|
22
|
+
|
21
23
|
CanBe::Builder::CanBe.build(self)
|
22
24
|
end
|
23
25
|
|
24
|
-
def can_be_detail(can_be_model
|
25
|
-
CanBe::Config.add_detail_model self, can_be_model, can_be_type
|
26
|
+
def can_be_detail(can_be_model)
|
26
27
|
CanBe::Builder::CanBeDetail.build(self, can_be_model)
|
27
28
|
end
|
28
29
|
end
|
data/lib/can_be/version.rb
CHANGED
data/spec/can_be/config_spec.rb
CHANGED
@@ -48,14 +48,14 @@ describe CanBe::Config do
|
|
48
48
|
|
49
49
|
context "#add_detail_model" do
|
50
50
|
it "adds the detail information" do
|
51
|
-
|
52
|
-
|
51
|
+
subject.add_details_model :type1, :config_spec_model
|
52
|
+
subject.details[:type1].should == :config_spec_model
|
53
53
|
end
|
54
54
|
|
55
55
|
it "adds the detail information for a second record" do
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
subject.add_details_model :type1, :config_spec_model
|
57
|
+
subject.add_details_model :type1, :config_spec_model2
|
58
|
+
subject.details[:type1].should == :config_spec_model2
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/spec/support/models.rb
CHANGED
@@ -12,15 +12,18 @@ class Person < ActiveRecord::Base
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Upload < ActiveRecord::Base
|
15
|
-
can_be :image_upload, :video_upload, :thumbnail_upload, :document_upload, :pdf_upload
|
15
|
+
can_be :image_upload, :video_upload, :thumbnail_upload, :document_upload, :pdf_upload do
|
16
|
+
add_details_model :image_upload, :image_upload_detail
|
17
|
+
add_details_model :video_upload, :video_upload_detail
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
class ImageUploadDetail < ActiveRecord::Base
|
19
|
-
can_be_detail :upload
|
22
|
+
can_be_detail :upload
|
20
23
|
end
|
21
24
|
|
22
25
|
class VideoUploadDetail < ActiveRecord::Base
|
23
|
-
can_be_detail :upload
|
26
|
+
can_be_detail :upload
|
24
27
|
end
|
25
28
|
|
26
29
|
class ThumbnailUploadDetail < ActiveRecord::Base
|