infix 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 395a7bf439a327207a0685c869b781e4ba192740b3163c973007645716966401
4
- data.tar.gz: 68418b3c3e2e66fd413828520194d863cc144d79263c98476ef5d1eabf1daca2
3
+ metadata.gz: 7cdc9fd160cadb0271707d51642d38be13527c7d40beff857550ecb4011d5159
4
+ data.tar.gz: 781f64a6545e86f29b9cf758c454d12ae5cf6907d12602e7df1b0d4905b4f496
5
5
  SHA512:
6
- metadata.gz: 0cd7e08f2edc028d1e713676067333952d13850bd6194a62385ed99fb8c9dbe7f03241aade75f18ae479c94dd41d1be492658ab6108ec9d2ec19106cea8e1a4e
7
- data.tar.gz: b945b080fde2ca1cde6276f3829d09aeddbe3c57df602f067d0ddadea71318a7770b542e2fe552acc8bc15587e9fd028b850f25712a0ba1f05a438238d00b62f
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.1"
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
- puts b.infix[:topspeed] #=> Outputs '24'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Infix
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rory Dudley