florrick 1.1.0 → 1.1.1

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
  SHA1:
3
- metadata.gz: d99e1315bb37101ae10cb3e6dbbb72abc0af64e5
4
- data.tar.gz: 8373a863cb8713c6bddeb554cfa0f127acfa21e1
3
+ metadata.gz: 495895562e335c2a36e35c3a6bdd8476a2756a1d
4
+ data.tar.gz: a970aad1d680cf16079543a0ddb6970ddad5a319
5
5
  SHA512:
6
- metadata.gz: 86cae527b35f612d7cbf198c0e0756c33410f9e2aa06cb10b1306d46113a3693702a4b53f5e9788e92efdc3080e0984f95f58f573b8c0d4588ded828b8de81e0
7
- data.tar.gz: 9ffeda401001ade5e88b2b67dbf4d8c95889d173e0dcc2b8416ded9e96a895a03088c1cbf7d907451789bcc67779e6eb0cb1d16b80cdfa6521e3ff6c17fa6bf7
6
+ metadata.gz: eecfa6c2b2e54e7e6b8c54d67b743dae428e9c158727867ce69b50aeaef17cdc632d7248a83ea9fe19a175db5ce8ef8f2a200dfb71010c16237f69717d215e76
7
+ data.tar.gz: 797bf52c99f07d9eea0dd2413bbb6dda79ae745b11de23cff5f25412cb00b8abed2033da4e271b9dfeccb5dc9b49429b83c03a394751e770949c95979be24f53
@@ -1,10 +1,10 @@
1
1
  module Florrick
2
2
  module ActiveRecordExtension
3
-
3
+
4
4
  def self.included(base)
5
5
  base.extend ClassMethods
6
6
  end
7
-
7
+
8
8
  def string_interpolation_value_for(var)
9
9
  if self.class.florrick_fields[:strings].keys.include?(var.to_sym)
10
10
  block = self.class.florrick_fields[:strings][var.to_sym]
@@ -17,7 +17,7 @@ module Florrick
17
17
  false
18
18
  end
19
19
  end
20
-
20
+
21
21
  module ClassMethods
22
22
 
23
23
  #
@@ -26,7 +26,7 @@ module Florrick
26
26
  def florrick_fields
27
27
  @florrick_fields ||= {:strings => {}, :relationships =>{}}
28
28
  end
29
-
29
+
30
30
  #
31
31
  # Accept a new set of configuration for this model
32
32
  #
@@ -35,21 +35,21 @@ module Florrick
35
35
  dsl.instance_eval(&block)
36
36
  dsl
37
37
  end
38
-
38
+
39
39
  #
40
40
  # Return whether or not a given key can be replaced
41
41
  #
42
42
  def string_interpolation_for?(var)
43
43
  florrick_fields[:strings].keys.include?(var.to_sym)
44
44
  end
45
-
45
+
46
46
  #
47
- # Return whether or not a given relationship key can be replaced
47
+ # Return whether or not a given relationship key can be replaced
48
48
  #
49
49
  def string_interpolation_relationship_for?(var)
50
50
  florrick_fields[:relationships].keys.include?(var.to_sym)
51
51
  end
52
52
  end
53
-
53
+
54
54
  end
55
55
  end
@@ -1,7 +1,7 @@
1
1
  module Florrick
2
2
  class Builder
3
3
 
4
- VALID_EXPORT_TYPES = [String, Numeric, Date, Time]
4
+ VALID_EXPORT_TYPES = [String, Numeric, Date, Time, Array]
5
5
 
6
6
  attr_reader :original_string, :objects
7
7
 
@@ -32,8 +32,8 @@ module Florrick
32
32
  if previous_object.class.string_interpolation_for?(var)
33
33
  # we can do this easily
34
34
  previous_object = previous_object.string_interpolation_value_for(var)
35
- # if the previous object was nil, just set to an empty string
36
- final_string = "" if previous_object.nil?
35
+ # if the previous object was nil, just set to the fallback string or empty
36
+ final_string = fallback_string || '' if previous_object.nil?
37
37
  elsif previous_object.class.string_interpolation_relationship_for?(var)
38
38
  # maybe we can do this on another object
39
39
  previous_object = previous_object.send(var)
@@ -52,13 +52,19 @@ module Florrick
52
52
  # we're at the end now, if we can return the previous object, lets do it otherwise
53
53
  # we'll just return the string as we can't do anything.
54
54
  if VALID_EXPORT_TYPES.any? { |t| previous_object.is_a?(t)}
55
- final_string = previous_object.to_s
55
+ final_string = previous_object
56
56
  else
57
57
  final_string = fallback_string || original_string
58
58
  end
59
59
  end
60
60
  end
61
- final_string
61
+
62
+ case final_string
63
+ when Array
64
+ final_string.join(", ")
65
+ else
66
+ final_string.to_s
67
+ end
62
68
  end
63
69
  end
64
70
 
@@ -12,6 +12,7 @@ require 'digest/md5'
12
12
  Florrick::Formatter.add('downcase', [String]) { |s| s.downcase }
13
13
  Florrick::Formatter.add('upcase', [String]) { |s| s.upcase }
14
14
  Florrick::Formatter.add('humanize', [String]) { |s| s.humanize }
15
+ Florrick::Formatter.add('capitalize', [String]) { |s| s.capitalize }
15
16
  Florrick::Formatter.add('strip', [String]) { |s| s.strip }
16
17
  Florrick::Formatter.add('sha1', [String]) { |s| Digest::SHA1.hexdigest(s) }
17
18
  Florrick::Formatter.add('md5', [String]) { |s| Digest::MD5.hexdigest(s) }
@@ -22,6 +23,15 @@ Florrick::Formatter.add('md5', [String]) { |s| Digest::MD5.hexdigest(s) }
22
23
  Florrick::Formatter.add('double', [Numeric]) { |s| s * 2 }
23
24
  Florrick::Formatter.add('triple', [Numeric]) { |s| s * 3 }
24
25
 
26
+ #
27
+ # Array formatters
28
+ #
29
+ Florrick::Formatter.add('join_with_commas', [Array]) { |a| a.join(', ')}
30
+ Florrick::Formatter.add('join_with_spaces', [Array]) { |a| a.join(' ') }
31
+ Florrick::Formatter.add('join_with_new_lines', [Array]) { |a| a.join("\n") }
32
+ Florrick::Formatter.add('as_list', [Array]) { |a| a.map { |v| "* #{v}"}.join("\n") }
33
+ Florrick::Formatter.add('to_sentence', [Array]) { |a| a.to_sentence }
34
+
25
35
  #
26
36
  # DateTime formatters
27
37
  #
data/lib/florrick/dsl.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  module Florrick
2
2
  class DSL
3
-
3
+
4
4
  def initialize(model)
5
5
  @model = model
6
6
  end
7
-
7
+
8
8
  def string(*vars, &block)
9
9
  vars.each do |var|
10
10
  @model.florrick_fields[:strings][var.to_sym] = block
11
11
  end
12
12
  end
13
-
13
+
14
14
  def relationship(*vars, &block)
15
15
  vars.each do |var|
16
16
  @model.florrick_fields[:relationships][var.to_sym] = block
@@ -1,3 +1,3 @@
1
1
  module Florrick
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: florrick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-31 00:00:00.000000000 Z
11
+ date: 2015-02-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Rails extension for providing awesome user-initiated string interpolation
14
14
  email: