liquid-hash-or-array-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: 707100ec7c513639145fe2efc3aee68b93f4ee04
4
+ data.tar.gz: 4e3186fd7d86b0168c89056f203c5bdd4f6c559d
5
+ SHA512:
6
+ metadata.gz: 711d6723d495d6ba6628e6987924d5e526a5396515d3118a8f55d66eb2e97d2db615a614a785fd2041adbc7d02ec9c52650f5d4cdb3b6ae41c1bd647bc89cc2c
7
+ data.tar.gz: 9c461614d98ee584aab7efb76315ede9ca0b0c96fd62f5664498a0491cc7a5b3fbdae5f7b8e28c1114a2219e7d07da158cb4883626126122a7bdc2be008de6c5
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2017 Jordon Bedwell - MIT License
3
+ # Encoding: utf-8
4
+
5
+ source "https://rubygems.org"
6
+ gemspec
7
+
8
+ gem "rake"
9
+ gem "pry"
@@ -0,0 +1,67 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2017 Jordon Bedwell - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "forwardable/extended"
6
+ require "liquid/drop"
7
+
8
+ module Liquid
9
+ class Drop
10
+ class HashOrArray < Drop
11
+ extend Forwardable::Extended
12
+
13
+ # --
14
+ # @return [<HashOrArray>] the instance
15
+ # There is no need for explaining it.
16
+ # --
17
+ def initialize(data)
18
+ @data = data
19
+ end
20
+
21
+ # --
22
+ # @return [<Any>] the value or nil.
23
+ # Standard hash method so that you can also access
24
+ # the data like a hash/array.
25
+ # --
26
+ def [](key)
27
+ liquid_method_missing(key)
28
+ end
29
+
30
+ # --
31
+ # Uses Liquids method missing method to get the key
32
+ # when you try and access the drop like a chained method
33
+ # we do the case because oen day we might split out the
34
+ # class and it would require minimal refactor.
35
+ # @return [<Any>] the value or nil.
36
+ # --
37
+ def liquid_method_missing(key)
38
+ val = @data.fetch(key.to_s, @data[key.to_sym])
39
+
40
+ case true
41
+ when val.is_a?(Array) then HashOrArray.new(val)
42
+ when val.is_a?( Hash) then HashOrArray.new(val)
43
+ else
44
+ val
45
+ end
46
+ end
47
+
48
+ # --
49
+ # Delegate methods directly to the hash or the Array,
50
+ # we don't need to carry these, enumerable does.
51
+ # --
52
+
53
+ rb_delegate :keys, to: :@data
54
+ rb_delegate :last, to: :@data
55
+ rb_delegate :each, to: :@data
56
+ rb_delegate :first, to: :@data
57
+ rb_delegate :values, to: :@data
58
+ rb_delegate :each_with_index, to: :@data
59
+ rb_delegate :inspect, to: :@data
60
+ rb_delegate :to_enum, to: :@data
61
+ rb_delegate :fetch, to: :@data
62
+ rb_delegate :to_h, to: :@data
63
+ rb_delegate :to_a, to: :@data
64
+ rb_delegate :map, to: :@data
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,12 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2017 Jordon Bedwell - MIT License
3
+ # Encoding: utf-8
4
+
5
+
6
+ module Liquid
7
+ class Drop
8
+ class HashOrArray < Drop
9
+ VERSION = "1.0.0"
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liquid-hash-or-array-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-14 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: forwardable-extended
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: liquid
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '4.0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '4.0'
75
+ description: A drop that wraps hashes and arrays.
76
+ email:
77
+ - jordon@envygeeks.io
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - Gemfile
83
+ - lib/liquid/drop/hash_or_array.rb
84
+ - lib/liquid/drop/hash_or_array/version.rb
85
+ homepage: http://github.com/envygeeks/liquid-string-drop
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 2.1.0
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.11
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: A drop for hashes and arrays.
109
+ test_files: []