material 0.3.6 → 0.3.7

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: 829e842bd296febb415517624619080df2a8a9cd838e5efc3ba4357966dd2185
4
- data.tar.gz: 06a84a9858a6788ef633ca6e6d13e4019a3f03651dbcb09ffc58cfce68d2aa6a
3
+ metadata.gz: 3e2eaa26ed95bfacb3d5457d2e94255f7cba64ca9457db9cf5a59c0ec6d25bb4
4
+ data.tar.gz: 9599971fef04642baaf5d1f5618eb626795cb52cd52a0c95f274a5a28ea170cd
5
5
  SHA512:
6
- metadata.gz: f7e1936b45f4019b3098b0445a9915f28f02a79942b7056b334d6f520298487af31d5143892a2d847abb4f1089eea25e013ba74aadc2a6e8cba7c660ed2047d7
7
- data.tar.gz: 49a6ad076b235f9f3669a11b54a421371b47a9a89f4a59e337e948c2a5b7b43df7e152e187194eab23af6833d919aa1539b4a9d63b6ff30c2523f8686067c363
6
+ metadata.gz: 3eee4688baab8826d259d125552cd442ffe175439c144292d284a72162f6dc67f18b20605e96665ab7c11d5661e707a122b21205dc783363c1677a363f30b438
7
+ data.tar.gz: d591fec54a9a2421f9b25e9eac798e511b1a1077fa5bcc3972f1043318166e7dd73c195010023066d13e5e656f233ea3b9a1acf758a6d1764a74b260f38a7a7a
@@ -7,6 +7,14 @@ module Material
7
7
  DEFAULT_TRUNCATE_LENGTH = 50
8
8
 
9
9
  class_methods do
10
+ def default_truncation_length
11
+ DEFAULT_TRUNCATE_LENGTH
12
+ end
13
+
14
+ def truncation_length(key)
15
+ public_send("#{key}_component".to_sym).options[:max_length] || default_truncation_length
16
+ end
17
+
10
18
  private
11
19
 
12
20
  def register_title_truncator(key)
@@ -17,29 +25,27 @@ module Material
17
25
  register_truncator(key) { title.pluralize }
18
26
  end
19
27
 
20
- def register_truncator(key, max_length = DEFAULT_TRUNCATE_LENGTH, &block)
28
+ def register_truncator(key, max_length = nil, &block)
21
29
  register_component(key, max_length: max_length, &block)
22
30
  define_truncation_formatter(key)
23
31
  define_truncation_predicate(key)
24
32
  end
25
33
 
26
34
  def define_truncation_formatter(key)
27
- define_method(key) do
28
- public_send("#{key}_value".to_sym).truncate(public_send("#{key}_component".to_sym).options[:max_length])
29
- end
35
+ define_method(key) { public_send("#{key}_value".to_sym).truncate(truncation_length(key)) }
30
36
  memoize key
31
37
  end
32
38
 
33
39
  def define_truncation_predicate(key)
34
40
  method_name = "#{key}_truncated?".to_sym
35
- define_method(method_name) do
36
- public_send("#{key}_value".to_sym).length > public_send("#{key}_component".to_sym).options[:max_length]
37
- end
41
+ define_method(method_name) { public_send("#{key}_value".to_sym).length > truncation_length(key) }
38
42
  memoize method_name
39
43
  end
40
44
  end
41
45
 
42
46
  included do
47
+ delegate :truncation_length, to: :class
48
+
43
49
  register_truncator(:title) { default_title.titleize }
44
50
 
45
51
  register_component(:parameterized_title) { title_value.underscore.parameterize }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Material
4
- VERSION = "0.3.6"
4
+ VERSION = "0.3.7"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: material
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-10 00:00:00.000000000 Z
12
+ date: 2020-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport