effective_resources 1.8.2 → 1.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/has_many_rich_texts.rb +10 -9
- data/lib/effective_resources/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e9efd79bdfd45a008026c4df5eb078e141ce8291c01942aea6b40565434be38
|
4
|
+
data.tar.gz: 8f31ee7e20b727cab52b580a470a74c00d64e1f830e76153d080dab7f9788645
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e7bd31331526a1f9bd7d68022d5cf8587c21ed142c06e8353e2b14ea1d3acc5a26af54d69dacdce1469159b0e55c4698b381fa027067dbcf1b688d47ad42f2b
|
7
|
+
data.tar.gz: ac2ffd7ccd01c8f016a99bf2f7dc6472b356a4dc489d1cdf5109fbb96bba36b642859bd28b14216b60b03309c830905b828e7f422dbc924325bd74fb9d6442b6
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# HasManyRichTexts
|
2
2
|
#
|
3
|
-
# Mark your model with 'has_many_rich_texts'
|
3
|
+
# Mark your model with 'has_many_rich_texts'
|
4
|
+
# Then it will automatically create a region when using a method named rich_text_*
|
5
|
+
# object.rich_text_body = "<p>Stuff</p>"
|
6
|
+
# object.rich_text_body => ActionText::RichText<name="body" body="<p>Stuff</p>">
|
4
7
|
|
5
8
|
module HasManyRichTexts
|
6
9
|
extend ActiveSupport::Concern
|
@@ -25,17 +28,14 @@ module HasManyRichTexts
|
|
25
28
|
rich_texts.find { |rt| rt.name == name } || rich_texts.build(name: name)
|
26
29
|
end
|
27
30
|
|
28
|
-
def
|
31
|
+
def assign_rich_text_body(name, body)
|
29
32
|
rich_text(name).assign_attributes(body: body)
|
30
33
|
end
|
31
34
|
|
32
35
|
# Prevents an ActiveModel::UnknownAttributeError
|
33
36
|
# https://github.com/rails/rails/blob/main/activemodel/lib/active_model/attribute_assignment.rb#L48
|
34
37
|
def respond_to?(*args)
|
35
|
-
|
36
|
-
return false if ['to_a', 'to_ary'].any? { |str| method == str }
|
37
|
-
return false if ['_by', '_at', '_id', '_by=', '_at=', 'id='].any? { |str| method.end_with?(str) }
|
38
|
-
true
|
38
|
+
args.first.to_s.start_with?('rich_text_') ? true : super
|
39
39
|
end
|
40
40
|
|
41
41
|
def method_missing(method, *args, &block)
|
@@ -43,11 +43,12 @@ module HasManyRichTexts
|
|
43
43
|
super unless respond_to?(method)
|
44
44
|
|
45
45
|
method = method.to_s
|
46
|
+
name = method.chomp('=').sub('rich_text_', '')
|
46
47
|
|
47
|
-
if method.end_with?('=')
|
48
|
-
send(:
|
48
|
+
if method.end_with?('=')
|
49
|
+
send(:assign_rich_text_body, name, *args)
|
49
50
|
elsif args.length == 0
|
50
|
-
send(:rich_text,
|
51
|
+
send(:rich_text, name, *args)
|
51
52
|
else
|
52
53
|
super
|
53
54
|
end
|