infix 0.1.0 → 0.2.0
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/README.md +5 -3
- data/lib/infix/version.rb +1 -1
- data/lib/infix.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cdc9fd160cadb0271707d51642d38be13527c7d40beff857550ecb4011d5159
|
4
|
+
data.tar.gz: 781f64a6545e86f29b9cf758c454d12ae5cf6907d12602e7df1b0d4905b4f496
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 695b776d519328493bf4433d52333f8f819d23a0e3d2d1225f10841740e176f7fe8157f38dcbe1c12928dbfc0c9b90f75bad95828dd9c99a2ffaff6ab9a0a986
|
7
|
+
data.tar.gz: 4a6df9fe4b1549bd79f546f597eb03cd31083175d3b5dcc45d6270a7d87f00b11a956544ee6df5d6ef507e03f7592935c83e0047545df059e7919fb5705a18a5
|
data/README.md
CHANGED
@@ -7,14 +7,14 @@ Infix is a simple, drop-in DSL for configuring any Ruby class.
|
|
7
7
|
In your Gemfile, place the following line:
|
8
8
|
|
9
9
|
```
|
10
|
-
gem "infix", "~> 0.
|
10
|
+
gem "infix", "~> 0.2"
|
11
11
|
```
|
12
12
|
|
13
13
|
The run `bundle` to install.
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
-
To use Infix, simply require it, then include it in your class. You will be able to access your configuration options using the `infix` method on the class instance. Similarly, you use the `infix` method, and pass it a block, in order to set preferences.
|
17
|
+
To use Infix, simply require it, then include it in your class. You will be able to access your configuration options using the `infix` method on the class instance (with hash indexing notation, or with OpenStruct notation). Similarly, you use the `infix` method, and pass it a block, in order to set preferences.
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
require "infix"
|
@@ -37,7 +37,9 @@ end
|
|
37
37
|
|
38
38
|
puts b.infix[:type] #=> Outputs 'european'
|
39
39
|
puts b.infix[:carrying] #=> Outputs 'coconut'
|
40
|
-
|
40
|
+
|
41
|
+
# Also works with OpenStruct syntax
|
42
|
+
puts b.infix.topspeed #=> Outputs '24'
|
41
43
|
```
|
42
44
|
|
43
45
|
You can also have nested structues inside your infix block.
|
data/lib/infix/version.rb
CHANGED
data/lib/infix.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "infix/version"
|
4
|
+
require "ostruct"
|
4
5
|
|
5
6
|
# Infix: Include this module to configure your classes
|
6
7
|
module Infix
|
7
8
|
def infix(&block)
|
8
|
-
return @infix ||= {} unless block_given?
|
9
|
+
return structurize(@infix ||= {}) unless block_given?
|
9
10
|
|
10
11
|
@infix ||= {}
|
11
12
|
@nest = []
|
@@ -36,4 +37,11 @@ module Infix
|
|
36
37
|
tree[nest[idx]] ||= {}
|
37
38
|
nested(tree[nest[idx]], nest, idx + 1, key, val)
|
38
39
|
end
|
40
|
+
|
41
|
+
def structurize(hash)
|
42
|
+
hash.each do |k, v|
|
43
|
+
hash[k] = structurize(v) if v.instance_of?(Hash)
|
44
|
+
end
|
45
|
+
OpenStruct.new(hash)
|
46
|
+
end
|
39
47
|
end
|