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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc4db438688ecdd123360281ec6cfbe5b7aede01451615bcee92c566f186081c
4
- data.tar.gz: fa9154d7b1942bd0e8023f8795b670313260bc0cb7c22b84f2cd9c8d993e8ee1
3
+ metadata.gz: 3e9efd79bdfd45a008026c4df5eb078e141ce8291c01942aea6b40565434be38
4
+ data.tar.gz: 8f31ee7e20b727cab52b580a470a74c00d64e1f830e76153d080dab7f9788645
5
5
  SHA512:
6
- metadata.gz: 80b67a72b7a4f700b788d906a4db3c7e6e58f758f1d8f64d31178875c11c8021df2c706b86763efeba151a44b62cd07d19b46b0c2d354a20dd0831ee04aef89f
7
- data.tar.gz: 1f18e82c58fdae3ff884659c7166825727a19e90a28a55add1d952dea32e7ee3cdabe1bf251b7bbb83d8c72017c99df22defffedf8d9720092a24876c212175b
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' and then any method missing is a rich text region
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 rich_text_body=(name, body)
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
- method = args.first.to_s
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?('=') && args.length == 1 && (args.first.kind_of?(String) || args.first.kind_of?(NilClass))
48
- send(:rich_text_body=, method.chomp('='), *args)
48
+ if method.end_with?('=')
49
+ send(:assign_rich_text_body, name, *args)
49
50
  elsif args.length == 0
50
- send(:rich_text, method, *args)
51
+ send(:rich_text, name, *args)
51
52
  else
52
53
  super
53
54
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.8.2'.freeze
2
+ VERSION = '1.8.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect