liquid-string-drop 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 288b61a2ba92e46f994f77c787c55908cffe6cfa
4
+ data.tar.gz: 64006ee7279f198a84267132a05ea9e553a1051d
5
+ SHA512:
6
+ metadata.gz: 81bf68eb502af8df3572ba4cdc517841ec4ead7905b40dda445e7281ca11db4c9a5c4dff0f8b8ef98f9ea621c4790ff279edaa6acf71d157f7bc45cfd9e52c89
7
+ data.tar.gz: 89db1e4de3145c4a774d0628578faa0406a114d28c55a11c6b056cbcb693abae5466725710759339404879b666be4fe9c67ec7126d4849b48e7bd1509f9111df
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem "rake"
5
+ gem "pry"
@@ -0,0 +1,85 @@
1
+ module Liquid
2
+ class Drop
3
+ class Str < String
4
+ attr_writer :context
5
+
6
+ # --
7
+ # Mocks `#is_a?` so that Liquid thinks we are a
8
+ # drop. If it ever decides to ask.
9
+ # --
10
+ def is_a?(v)
11
+ v == Liquid::Drop || super(v)
12
+ end
13
+
14
+ # --
15
+ # Liquid version of `method_missing`, except it only
16
+ # works for Liquid and only takes the method.
17
+ # @return Error.
18
+ # --
19
+ def liquid_method_missing(method)
20
+ return nil unless @context && @context.strict_variables
21
+ raise Liquid::UndefinedDropMethod, \
22
+ "undefined method #{method}"
23
+ end
24
+
25
+ # --
26
+ # Invokes a method on the drop if it exist and is
27
+ # not blacklisted. We blacklist most methods by
28
+ # default if it's on `String`, `Array`, `Enumberable`
29
+ # `Hash` and this own class...
30
+ # --
31
+ def invoke_drop(m)
32
+ self.class.invokable?(m) ? send(m) : liquid_method_missing(m)
33
+ end
34
+
35
+ # --
36
+ def to_liquid
37
+ self
38
+ end
39
+
40
+ # --
41
+ def key?(_)
42
+ true
43
+ end
44
+
45
+ # --
46
+ # This is `.invokable?` when it comes to Liquids own
47
+ # source. We change it to discourage users from overriding
48
+ # the methods because this is a wrapper.
49
+ # --
50
+ def self.invokable?(m)
51
+ invokable_methods.include?(m.to_s)
52
+ end
53
+
54
+ # --
55
+ def self.invokable_methods
56
+ @invokable_methods ||= begin
57
+ Set.new(good.map(&:to_s))
58
+ end
59
+ end
60
+
61
+ private
62
+ def self.bad
63
+ @bad ||= begin bad = []
64
+ bad = bad | Drop.public_instance_methods
65
+ bad = bad | Array.public_instance_methods
66
+ bad = bad | Enumerable.public_instance_methods
67
+ bad = bad | String.public_instance_methods
68
+ bad = bad | Hash.public_instance_methods
69
+ end
70
+ end
71
+
72
+ private
73
+ def self.good
74
+ @good ||= [:to_liquid] | (
75
+ public_instance_methods - bad
76
+ )
77
+ end
78
+
79
+ # --
80
+
81
+ alias_method :===, :is_a?
82
+ alias_method :[], :invoke_drop
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,7 @@
1
+ module Liquid
2
+ class Drop
3
+ class Str < String
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liquid-string-drop
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordon Bedwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
33
+ - !ruby/object:Gem::Dependency
34
+ name: luna-rspec-formatters
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.7'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.7'
47
+ - !ruby/object:Gem::Dependency
48
+ name: liquid
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '4.0'
61
+ description: A drop that can be a string too
62
+ email:
63
+ - jordon@envygeeks.io
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - Gemfile
69
+ - lib/liquid/drop/str.rb
70
+ - lib/liquid/drop/str/version.rb
71
+ homepage: http://github.com/envygeeks/liquid-string-drop
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.1.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.11
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A drop that is also a string
95
+ test_files: []