given_keyword_args 0.1.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: 921a7139565017d683667ad382ad246aa3e850ca
4
+ data.tar.gz: dec27c01c11ddd90b94579cb4925915a2b6aeef2
5
+ SHA512:
6
+ metadata.gz: d3509c7ed2168c461b3c72f7da4290c17a0a7b84858c8b48ae807bc5b4df1c12299b359373dbaf8106c984066c20a2db5f10e98ea0fb40c1dbb6379dd8a7a4a2
7
+ data.tar.gz: 23069bb6731519febf1824356b7b47db2f0254c35e0d29df6db8870e20855eb0f6b600a66b4b4474d6b1ee742566e932ce33ddba9b5cacebd511e749e140ff8b
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /Makefile
12
+ /lib/given_keyword_args/given_keyword_args.bundle
13
+ /lib/given_keyword_args/given_keyword_args.so
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in given_keyword_args.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ # GivenKeywordArgs
2
+
3
+ Add `given_keyword_args` and `given_keyword_args_with_rest` method to `Object`.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'given_keyword_args'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install given_keyword_args
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ class Dummy
25
+ def dummy(foo:, bar: "bar", **options)
26
+ given_keyword_args
27
+ end
28
+
29
+ def dummy_with_rest(foo:, bar: "bar", **options)
30
+ given_keyword_args_with_rest
31
+ end
32
+ end
33
+
34
+ Dummy.new.dummy(foo: "foo", other1: "other1", other2: "other2") # => {foo: "foo", bar: "bar"}
35
+ Dummy.new.dummy_with_rest(foo: "foo", other1: "other1", other2: "other2") # => {foo: "foo", bar: "bar", other1: "other1", other2: "other2"}
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joker1007/given_keyword_args.
47
+
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/extensiontask"
3
+ require "rspec/core/rake_task"
4
+
5
+ Rake::ExtensionTask.new('given_keyword_args') do |ext|
6
+ ext.lib_dir = 'lib/given_keyword_args'
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task :default => [:compile, :spec]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "given_keyword_args"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+
3
+ create_makefile 'given_keyword_args/given_keyword_args'
@@ -0,0 +1,28 @@
1
+ #include <ruby.h>
2
+ #include <ruby/intern.h>
3
+
4
+ static VALUE
5
+ ruby_given_keyword_args(VALUE self)
6
+ {
7
+ VALUE binding = rb_binding_new();
8
+ VALUE fname = rb_frame_callee();
9
+ VALUE mname = rb_funcall(self, rb_intern("__method__"), 0);
10
+ return rb_funcall(self, rb_intern("__given_keyword_args__"), 2, binding, Qfalse);
11
+ }
12
+
13
+ static VALUE
14
+ ruby_given_keyword_args_with_rest(VALUE self)
15
+ {
16
+ VALUE binding = rb_binding_new();
17
+ VALUE fname = rb_frame_callee();
18
+ VALUE mname = rb_funcall(self, rb_intern("__method__"), 0);
19
+ return rb_funcall(self, rb_intern("__given_keyword_args__"), 2, binding, Qtrue);
20
+ }
21
+
22
+ void
23
+ Init_given_keyword_args(void)
24
+ {
25
+ VALUE module = rb_define_module("GivenKeywordArgs");
26
+ rb_define_private_method(module, "given_keyword_args", ruby_given_keyword_args, 0);
27
+ rb_define_private_method(module, "given_keyword_args_with_rest", ruby_given_keyword_args_with_rest, 0);
28
+ }
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'given_keyword_args/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "given_keyword_args"
8
+ spec.version = GivenKeywordArgs::VERSION
9
+ spec.authors = ["joker1007"]
10
+ spec.email = ["kakyoin.hierophant@gmail.com"]
11
+
12
+ spec.summary = %q{Access Helper to all keyword args}
13
+ spec.description = %q{Access Helper to all keyword args}
14
+ spec.homepage = "https://github.com/joker1007/given_keyword_args"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ spec.extensions = ["ext/given_keyword_args/extconf.rb"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "rake-compiler"
26
+ end
@@ -0,0 +1,22 @@
1
+ require "given_keyword_args/version"
2
+
3
+ module GivenKeywordArgs
4
+ private
5
+
6
+ def __given_keyword_args__(local_binding, with_rest = false)
7
+ method_name = caller_locations[1].label
8
+ meth = method(method_name)
9
+ meth.parameters.each_with_object({}) do |(type, name), h|
10
+ if type == :key || type == :keyreq
11
+ h[name] = local_binding.local_variable_get(name)
12
+ elsif with_rest && type == :keyrest
13
+ value = local_binding.local_variable_get(name)
14
+ h.merge!(value) unless value.empty?
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ require 'given_keyword_args/given_keyword_args'
21
+
22
+ Object.include(GivenKeywordArgs)
@@ -0,0 +1,3 @@
1
+ module GivenKeywordArgs
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: given_keyword_args
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - joker1007
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Access Helper to all keyword args
70
+ email:
71
+ - kakyoin.hierophant@gmail.com
72
+ executables: []
73
+ extensions:
74
+ - ext/given_keyword_args/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - ext/given_keyword_args/extconf.rb
86
+ - ext/given_keyword_args/given_keyword_args.c
87
+ - given_keyword_args.gemspec
88
+ - lib/given_keyword_args.rb
89
+ - lib/given_keyword_args/version.rb
90
+ homepage: https://github.com/joker1007/given_keyword_args
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.4
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Access Helper to all keyword args
113
+ test_files: []