infix 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 395a7bf439a327207a0685c869b781e4ba192740b3163c973007645716966401
4
+ data.tar.gz: 68418b3c3e2e66fd413828520194d863cc144d79263c98476ef5d1eabf1daca2
5
+ SHA512:
6
+ metadata.gz: 0cd7e08f2edc028d1e713676067333952d13850bd6194a62385ed99fb8c9dbe7f03241aade75f18ae479c94dd41d1be492658ab6108ec9d2ec19106cea8e1a4e
7
+ data.tar.gz: b945b080fde2ca1cde6276f3829d09aeddbe3c57df602f067d0ddadea71318a7770b542e2fe552acc8bc15587e9fd028b850f25712a0ba1f05a438238d00b62f
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ Exclude:
4
+ - "test/test_infix.rb"
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 120
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Rory Dudley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # Infix
2
+
3
+ Infix is a simple, drop-in DSL for configuring any Ruby class.
4
+
5
+ ## Installation
6
+
7
+ In your Gemfile, place the following line:
8
+
9
+ ```
10
+ gem "infix", "~> 0.1"
11
+ ```
12
+
13
+ The run `bundle` to install.
14
+
15
+ ## Usage
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.
18
+
19
+ ```ruby
20
+ require "infix"
21
+
22
+ class Bird
23
+ include Infix
24
+
25
+ def initialize(name)
26
+ @name = name
27
+ end
28
+ end
29
+
30
+ bird = Bird.new('Swallow')
31
+
32
+ b.infix do
33
+ type :european
34
+ carrying "coconut"
35
+ topspeed 24
36
+ end
37
+
38
+ puts b.infix[:type] #=> Outputs 'european'
39
+ puts b.infix[:carrying] #=> Outputs 'coconut'
40
+ puts b.infix[:topspeed] #=> Outputs '24'
41
+ ```
42
+
43
+ You can also have nested structues inside your infix block.
44
+
45
+ ```ruby
46
+ b.infix do
47
+ film_references do
48
+ monty_python true
49
+ star_wars "no"
50
+ end
51
+ end
52
+
53
+ puts b.infix[:film_references][:monty_python] #=> Outputs 'true'
54
+ puts b.infix[:film_references][:star_wars] #=> Outputs 'no'
55
+ ```
56
+
57
+ Infix may also be useful for defining application options in a usual location (i.e. `~`, `~/.config`, `/etc`).
58
+
59
+ ```ruby
60
+ # ~/.birdrc
61
+
62
+ $bird.infix do
63
+ type :european
64
+ carrying "coconut"
65
+ topspeed 24
66
+ end
67
+ ```
68
+
69
+ ```ruby
70
+ require "infix"
71
+
72
+ class Bird
73
+ include Infix
74
+ end
75
+
76
+ $bird = Bird.new
77
+
78
+ config = File.expand_path("~/.birdrc")
79
+
80
+ require config if File.exist?(config)
81
+
82
+ puts $bird.infix #=> Outputs {:type=>:european, :carrying=>"coconut", :topspeed=>24}
83
+ ```
84
+
85
+ ## Development
86
+
87
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
88
+
89
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
90
+
91
+ ## Contributing
92
+
93
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pinecat/infix.
94
+
95
+ ## License
96
+
97
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Infix
4
+ VERSION = "0.1.0"
5
+ end
data/lib/infix.rb ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "infix/version"
4
+
5
+ # Infix: Include this module to configure your classes
6
+ module Infix
7
+ def infix(&block)
8
+ return @infix ||= {} unless block_given?
9
+
10
+ @infix ||= {}
11
+ @nest = []
12
+ instance_eval(&block)
13
+ end
14
+
15
+ def respond_to_missing?(name, include_private); end
16
+
17
+ def method_missing(key, val = nil, &block)
18
+ if block_given?
19
+ @nest << key
20
+ instance_eval(&block)
21
+ @nest.pop
22
+ elsif @nest.empty?
23
+ @infix[key] = val
24
+ else
25
+ nested(@infix, @nest, 0, key, val)
26
+ end
27
+ end
28
+
29
+ def nested(tree, nest, idx, key, val)
30
+ if idx == (nest.size - 1)
31
+ tree[nest[idx]] ||= {}
32
+ tree[nest[idx]][key] = val
33
+ return tree[nest[idx]]
34
+ end
35
+
36
+ tree[nest[idx]] ||= {}
37
+ nested(tree[nest[idx]], nest, idx + 1, key, val)
38
+ end
39
+ end
data/sig/infix.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Infix
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rory Dudley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Drop-in DSL config language for Ruby classes.
14
+ email:
15
+ - rory.dudley@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rubocop.yml"
21
+ - LICENSE.txt
22
+ - README.md
23
+ - Rakefile
24
+ - lib/infix.rb
25
+ - lib/infix/version.rb
26
+ - sig/infix.rbs
27
+ homepage: https://github.com/pinecat/infix
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ allowed_push_host: https://rubygems.org
32
+ homepage_uri: https://github.com/pinecat/infix
33
+ source_code_uri: https://github.com/pinecat/infix
34
+ changelog_uri: https://github.com/pinecat/infix
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.4.17
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Ruby based configurator.
54
+ test_files: []