florrick 1.1.1 → 1.1.2
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.
- checksums.yaml +4 -4
- data/lib/florrick.rb +2 -2
- data/lib/florrick/builder.rb +3 -1
- data/lib/florrick/formatter.rb +6 -6
- data/lib/florrick/railtie.rb +2 -2
- data/lib/florrick/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72ded218986890ab953e08fd2827246f536c98e6
|
4
|
+
data.tar.gz: e3499a4fb82bec5a3d5d0f0a4fd6db718ba7474e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 774763f7e32f619b9d3fd55726944cd9a14b485046ecbefef9269d701ced77e0c957996529861af11ca69968a023175641043dd072f9a459e54b917a760a9f9a
|
7
|
+
data.tar.gz: 48aaf1f0e22df3c6302c12ef6de6af79d2df94977b230bfed60aab6d7a6dd290a4630c6fe6b404ada233521ab7170a748f5a8438f8d85846420d4426dc37dd99
|
data/lib/florrick.rb
CHANGED
@@ -6,10 +6,10 @@ require 'florrick/builtin_formatters'
|
|
6
6
|
require 'florrick/railtie' if defined?(Rails)
|
7
7
|
|
8
8
|
module Florrick
|
9
|
-
|
9
|
+
|
10
10
|
# A quick helper method for quickly running conversion
|
11
11
|
def self.convert(string, objects = {})
|
12
12
|
Builder.new(string, objects).output
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
end
|
data/lib/florrick/builder.rb
CHANGED
@@ -33,7 +33,9 @@ module Florrick
|
|
33
33
|
# we can do this easily
|
34
34
|
previous_object = previous_object.string_interpolation_value_for(var)
|
35
35
|
# if the previous object was nil, just set to the fallback string or empty
|
36
|
-
|
36
|
+
if previous_object.nil? || (previous_object.is_a?(Array) && previous_object.empty?)
|
37
|
+
final_string = fallback_string || ''
|
38
|
+
end
|
37
39
|
elsif previous_object.class.string_interpolation_relationship_for?(var)
|
38
40
|
# maybe we can do this on another object
|
39
41
|
previous_object = previous_object.send(var)
|
data/lib/florrick/formatter.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module Florrick
|
2
2
|
class Formatter
|
3
|
-
|
3
|
+
|
4
4
|
class << self
|
5
5
|
# Return all formatters available
|
6
6
|
def formatters
|
7
7
|
@formatters ||= {}
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
# Add a new global formatter
|
11
11
|
def add(name, types = [], &block)
|
12
12
|
formatters[name.to_sym] = self.new(name, types, &block)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# Run a string through a given formatter and return the result. If not possible, return false.
|
16
16
|
def convert(name, value)
|
17
17
|
if formatter = formatters[name.to_sym]
|
@@ -21,11 +21,11 @@ module Florrick
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def initialize(name, types, &block)
|
26
26
|
@name, @types, @block = name, types, block
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def convert(value)
|
30
30
|
if @types.empty? || @types.any? { |t| value.is_a?(t)}
|
31
31
|
@block.call(value)
|
@@ -35,6 +35,6 @@ module Florrick
|
|
35
35
|
rescue
|
36
36
|
'???'
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
end
|
40
40
|
end
|
data/lib/florrick/railtie.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Florrick
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
-
|
3
|
+
|
4
4
|
initializer 'florrick.initialize' do
|
5
5
|
ActiveSupport.on_load(:active_record) do
|
6
6
|
require 'florrick/active_record_extension'
|
7
7
|
ActiveRecord::Base.send :include, Florrick::ActiveRecordExtension
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
end
|
12
12
|
end
|
data/lib/florrick/version.rb
CHANGED