methodz 0.1.6

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: dc8bad5a7b3c5aa07afb1c8a1d62d9ed337b54c4355bbbe779b022bcb5ca712b
4
+ data.tar.gz: f90d2f1d2e7c3b8454ac902670dd3fffa97327e78c75c7395e29f18c058c8de4
5
+ SHA512:
6
+ metadata.gz: f362e0a297b869e82eeb735a3c51357b4d200454499836082cbb8d8bf2770c7299c162ac134865bfdcf06d6a3d50f63eec7dba0318a532bd21427be470a65384
7
+ data.tar.gz: 9ddbe6407f54fac84eca9f8daf91ecec392a1b562f51fbd14e8d342eb1d1328fa4a44012c63e20efa51f0937f0dca18b33b4d00494cf3a927e0c27a0f950558f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Ryan Kulp
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,46 @@
1
+ # Methodz
2
+
3
+ Simple utility to query available object methods by partial name or type.
4
+
5
+ ```rb
6
+ user = User.last
7
+
8
+ # returns methods for this class only (ignores Object.methods, ActiveModel::Dirty, and attribute getter/setters)
9
+ user.methodz
10
+
11
+ # returns methods with 'stripe' partial match in definition
12
+ user.methodz('stripe')
13
+
14
+ # returns private methods with 'stripe' partial match
15
+ user.methodz(q: 'stripe', type: 'private')
16
+
17
+ # returns public methods with 'password' partial match
18
+ user.methodz(q: 'password', type: 'public')
19
+
20
+ # returns protected methods with 'customer' partial match
21
+ user.methodz(q: 'stripe', type: 'private')
22
+ ```
23
+
24
+ ## Installation
25
+
26
+ Install the gem and add to the application's Gemfile by executing:
27
+
28
+ $ bundle add methodz
29
+
30
+ If bundler is not being used to manage dependencies, install the gem by executing:
31
+
32
+ $ gem install methodz
33
+
34
+ ## Development
35
+
36
+ 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.
37
+
38
+ 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).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ryanckulp/methodz.
43
+
44
+ ## License
45
+
46
+ 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,27 @@
1
+ # frozen_string_literal: true
2
+ require 'git'
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[spec]
9
+
10
+ task :bump do
11
+ repo = Git.open('.')
12
+ version_file = './lib/methodz/version.rb'
13
+ matcher = /VERSION = '(.*)'\.freeze/
14
+
15
+ file_contents = File.read(version_file)
16
+
17
+ updated = file_contents.gsub(matcher) do |v|
18
+ v.gsub Regexp.last_match(1), Regexp.last_match(1).succ
19
+ end
20
+
21
+ File.open(version_file, 'w+') { |f| f << updated }
22
+
23
+ sh 'bundle'
24
+
25
+ repo.add(version_file)
26
+ repo.add('Gemfile.lock')
27
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Methodz
4
+ class ActiveRecord::Base
5
+ def methodz(opts = {})
6
+ list = public_methods + private_methods + protected_methods - Object.methods
7
+ return list if opts.empty?
8
+
9
+ # simple usage, ex: user.methodz('stripe')
10
+ opts = { q: opts } if opts.instance_of?(String)
11
+
12
+ # query by keyword in definition
13
+ list = list.filter { |m| m.to_s.include?(opts[:q] || '') }
14
+
15
+ # query specific types, ex: user.methodz('stripe', type: 'private')
16
+ if opts[:type] && !%w[all].include?(opts[:type])
17
+ list = list.filter { |m| send("#{opts[:type]}_methods").include?(m) }
18
+ end
19
+
20
+ # remove ActiveModel::Dirty helpers, ex: will_save_change_to_{query}
21
+ dirty_attrz.each { |da| list = list.filter { |m| !m.to_s.include?(da.to_s) } }
22
+ list = list.filter { |_| dirty_attrz.any? { |da| !da.to_s.include?(opts[:q] || '') } }
23
+
24
+ # remove getter/setter attributes (seeking user-defined methods, not activerecord given)
25
+ attrz.each { |a| list = list.filter { |m| !m.to_s.include?(a.to_s) } }
26
+
27
+ list
28
+ end
29
+
30
+ def attrz
31
+ return [] unless respond_to?(:attributes)
32
+
33
+ attributes.keys.map(&:to_sym)
34
+ end
35
+
36
+ # https://api.rubyonrails.org/classes/ActiveModel/Dirty.html
37
+ def dirty_attrz
38
+ %i[
39
+ restore_ will_save_change_to _change_to_be_saved _for_database
40
+ _before_last_save _in_database _change _was _id? _previously_was
41
+ _before_last_save_was _came_from_ _before_type_cast _changed?
42
+ ]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Methodz
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Methodz
4
+ VERSION = '0.1.6'.freeze
5
+ end
data/lib/methodz.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'methodz/version'
4
+ require 'methodz/error'
5
+ require 'methodz/core'
6
+
7
+ module Methodz
8
+ end
data/sig/methodz.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Methodz
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: methodz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Kulp
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-12-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - ryanckulp@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - LICENSE.txt
22
+ - README.md
23
+ - Rakefile
24
+ - lib/methodz.rb
25
+ - lib/methodz/core.rb
26
+ - lib/methodz/error.rb
27
+ - lib/methodz/version.rb
28
+ - sig/methodz.rbs
29
+ homepage: https://github.com/ryanckulp/methodz
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ homepage_uri: https://github.com/ryanckulp/methodz
34
+ source_code_uri: https://github.com/ryanckulp/methodz
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.13
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Lookup object methods by partial name match or type.
54
+ test_files: []