smart_method_parameters 0.0.2

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
+ SHA1:
3
+ metadata.gz: f59c6b869d26049b0152177c1d3e607805b365da
4
+ data.tar.gz: 8eddb8baf4965e9a53d27bf4dd8acb7d9779eea1
5
+ SHA512:
6
+ metadata.gz: cb20ff1f19e6ecbcddad5c0f60147ad4553c775df7beffad845feb703344b3fbd2c5cc3d2584169bdeb81b9fe76e3aec764d196b1842f3b9e0fc6561a99f099e
7
+ data.tar.gz: 8c797ed9272ac1be71c84411495bc48774fda9ca56ad311e2afdafe4e721684294ad0eb9097c61d79a03e957503c8abec1da8877df3f653180ad420272239cdb
data/README.rdoc ADDED
@@ -0,0 +1,62 @@
1
+ Smart Method Parameters
2
+ =======================
3
+
4
+ Advanced hash representation of method parameters and keyword parameters in Ruby ~> 2.1
5
+
6
+ Provides easy access toparameters as a hash and filtering.
7
+
8
+ Example:
9
+
10
+ ~~~
11
+ >> def send_email(text, signature = "See You", from:, to:, subject: nil, cc: nil, at: nil, **extra)
12
+ >> args = method_parameters(binding) # hash of method parameters
13
+ >> ...
14
+ >> end
15
+ ~~~
16
+
17
+ Hash of parameters has singleton methods to filter parameters by type
18
+
19
+ ~~~
20
+ >> args = send_email("test", :from => "me@a.com", :to => "you@b.com", :at => Time.now, :bcc => "one@c.com")
21
+ >> args.limit_to(:predefined)
22
+ => {
23
+ => :signature => "See You",
24
+ => :subject => nil,
25
+ => :cc => nil,
26
+ => :at => 2015-07-17 23:51:32 +0300
27
+ => }
28
+ ~~~
29
+
30
+ Setup
31
+ -----
32
+
33
+ ~~~
34
+ $ gem install smart_method_parameters
35
+ ~~~
36
+
37
+
38
+ == LICENSE
39
+
40
+ (The MIT License)
41
+
42
+ Copyright (c) 2015 Vladimir Gorodulin
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ 'Software'), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62
+
@@ -0,0 +1,6 @@
1
+ module SmartMethodParameters
2
+ VERSION_MAJOR = 0
3
+ VERSION_MINOR = 0
4
+ VERSION_PATCH = 2
5
+ VERSION = [VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH].join('.')
6
+ end
@@ -0,0 +1,56 @@
1
+ require "smart_method_parameters/version"
2
+ require "set"
3
+
4
+ module SmartMethodParameters
5
+ module Kernel
6
+
7
+ def method_parameters(b)
8
+ fail "binding expected" unless b.is_a? Binding
9
+ groupnames = [:keywords, :required, :positional, :optional, :predefined]
10
+ groups = Hash[groupnames.map {|x| [x, Set.new]}]
11
+ groupings = {
12
+ :req => %i(positional required),
13
+ :opt => %i(positional optional predefined),
14
+ :key => %i(keywords required predefined),
15
+ :keyreq => %i(keywords required),
16
+ :keyrest => %i(keywords optional),
17
+ }
18
+
19
+ hash = Hash.new
20
+ parameters = eval("method(__method__).parameters",b)
21
+ parameters.each do |pair|
22
+ ptype, pname = *pair
23
+ next if ptype == :rest
24
+ pvalue = eval(pname.to_s, b)
25
+ groupings[ptype].each do |groupname|
26
+ if ptype == :keyrest
27
+ groups[groupname].merge(pvalue.keys)
28
+ hash.merge! pvalue
29
+ else
30
+ groups[groupname] << pname
31
+ hash[pname] = pvalue
32
+ end
33
+ end
34
+ end
35
+
36
+ hash.define_singleton_method(:parameter_groups) {groups}
37
+ hash.define_singleton_method(:limit_to) do |*groupnames|
38
+ self if groupnames == []
39
+ self.select do |pname,pvalue|
40
+ groupnames.all? do |groupname|
41
+ groups[groupname].include? pname
42
+ end
43
+ end
44
+ end
45
+
46
+ hash
47
+ end
48
+
49
+
50
+ end
51
+ end
52
+
53
+
54
+ Kernel.send :include, SmartMethodParameters::Kernel
55
+ Object.send :include, Kernel
56
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_method_parameters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Gorodulin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gemma
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.1.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.1.0
33
+ description: Advanced hash representation of method parameters and keyword parameters
34
+ in Ruby 2.0
35
+ email:
36
+ - dustbin@4letters.ru
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files:
40
+ - README.rdoc
41
+ files:
42
+ - README.rdoc
43
+ - lib/smart_method_parameters.rb
44
+ - lib/smart_method_parameters/version.rb
45
+ homepage: http://lifespace.ru/
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options:
51
+ - "--main"
52
+ - README.rdoc
53
+ - "--title"
54
+ - smart_method_parameters-0.0.2 Documentation
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.5
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Smart Method Parameters
73
+ test_files: []
74
+ has_rdoc: