takes_macro 1.0.0 → 1.0.1
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/.github/workflows/ruby.yml +20 -0
- data/README.md +8 -3
- data/lib/takes_macro.rb +3 -2
- data/lib/takes_macro/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e316a40e16340852e1d13e80e76981c2d9904722894ce48eb2af2b85378d8df
|
4
|
+
data.tar.gz: 314c10bb6f31dae580b9d99b8365ac60403bba2a87d4eb7b514000755fc18b0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 691d558719fe4bbd72c7105e6ceb6fa56138fd3c1f6e14eb0a39385d0e00d7f9c1b4e3fefd00d9956238ad745661c5cd3e4fb5cc3f7b641ed9eaad8ff83f6c9a
|
7
|
+
data.tar.gz: 3a816029d1e337d2613bf7b8b83f617a7e02ebc98c50ef4fb9751d3a6b3e606c7680dd847369fa07b6a1d00b58e05e589763dc84b54b5cbde650fc9ebf6518f4
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby 2.6
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.6.x
|
16
|
+
- name: Build and test with Rake
|
17
|
+
run: |
|
18
|
+
gem install bundler
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
bundle exec rake
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# TakesMacro
|
2
2
|
|
3
|
+

|
4
|
+
|
5
|
+
|
3
6
|
[attr_extras][] is a **great** gem that lets you remove most of the boilerplate needed for creating different types of initializers in Ruby.
|
4
7
|
|
5
8
|
This gem contains a reimplementation of `pattr_initialize` from attr_extras that is much faster. If you're using attr_extras, but the only feature of it you're using is `pattr_initialize` then this gem is for you.
|
@@ -23,9 +26,11 @@ Run `bundle exec ruby benchmarks/takes_macro_vs_attr_extras.rb` to see how much
|
|
23
26
|
875.721k (± 5.8%) i/s - 4.424M in 5.071249s
|
24
27
|
|
25
28
|
Comparison:
|
26
|
-
takes_macro:
|
27
|
-
hand written initializer:
|
28
|
-
attr_extras:
|
29
|
+
takes_macro: 1208748.5 i/s
|
30
|
+
hand written initializer: 875721.1 i/s - 1.38x slower
|
31
|
+
attr_extras: 169352.8 i/s - 7.14x slower
|
32
|
+
|
33
|
+
The initializer generated by `takes` is faster than the hand written version because the `takes` version uses an options hash, and the hand written version uses keyword arguments, which are a bit slower. You can see the exact code for the benchmark [here](https://github.com/tonsser/takes_macro/blob/master/benchmarks/takes_macro_vs_attr_extras.rb).
|
29
34
|
|
30
35
|
## How it works
|
31
36
|
|
data/lib/takes_macro.rb
CHANGED
@@ -20,10 +20,11 @@ module TakesMacro
|
|
20
20
|
positional_args,
|
21
21
|
]
|
22
22
|
|
23
|
-
if keyword_args.
|
23
|
+
if keyword_args.one? && !keyword_args.first.include?("!")
|
24
|
+
args_code << "options = {}"
|
25
|
+
elsif keyword_args.any?
|
24
26
|
args_code << "options"
|
25
27
|
end
|
26
|
-
|
27
28
|
args_code = args_code.flatten.compact.join(", ")
|
28
29
|
|
29
30
|
bind_positional_args_code = positional_args.map do |arg|
|
data/lib/takes_macro/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: takes_macro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Pedersen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".github/workflows/ruby.yml"
|
90
91
|
- ".gitignore"
|
91
92
|
- ".travis.yml"
|
92
93
|
- Gemfile
|
@@ -117,8 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
118
|
- !ruby/object:Gem::Version
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
|
-
|
121
|
-
rubygems_version: 2.7.3
|
121
|
+
rubygems_version: 3.0.3
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Remove boilerplate for writing initializers
|