who_delegated 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: ff8900cab08a42676dba8802a3a9864c4ddfcca683836e82e7ef77bfaa5ddd9d
4
+ data.tar.gz: 666641bf2f910165ffcdc16c35269110e612608e77b6ef029674ef56985a3e35
5
+ SHA512:
6
+ metadata.gz: f3fed141d4e32b25ed23977388d76b71a77edc21d3b2e1bca1ddf09db447ca5a22a9ed8661540b99c87bd42ab79d2219fb75621a9cc04219463c782c7e7f56f1
7
+ data.tar.gz: '08e48fff955609091bcbcfce147962218bc673fd7e4dcb451ce8b439bd6c9890f78e5a6f6feac8d62968c4b2efac0311d3e8f17a9a54f4158e4741a625be4d96'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Sampo Kuokkanen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # who_delegated
2
+ This gem is a simple tool to help you find out if a method is delegated or not. My use case for it is when creating SQL queries, I want to find out whether the method is a delegated one, as we have some special logic for those cases.
3
+
4
+ Only works on ActiveRecord models, as I only need it there to find out if a method is backed by a column or not, and also figure out if it is a method on the object or if it's delegated.
5
+
6
+ ## Usage
7
+ The gem adds the method 'delegated?' to the ActiveRecord::Base. You can use it like this:
8
+
9
+ ```ruby
10
+ class User < ApplicationRecord
11
+ has_one :friend
12
+ delegate :name, to: :friend
13
+ end
14
+
15
+ User.new.delegated?(:name)
16
+ # => true
17
+ ```
18
+
19
+ ## Installation
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem "who_delegated"
24
+ ```
25
+
26
+ And then execute:
27
+ ```bash
28
+ $ bundle
29
+ ```
30
+
31
+ Or install it yourself as:
32
+ ```bash
33
+ $ gem install who_delegated
34
+ ```
35
+
36
+ ## Contributing
37
+ Contribution directions go here.
38
+
39
+ ## License
40
+ 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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+
5
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :who_delegated do
4
+ # # Task goes here
5
+ # end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # reopen ActiveRecord::Base to add delegated_method? method
4
+ module ActiveRecord
5
+ class Base # rubocop:todo Style/Documentation
6
+ def delegated_method?(method_name)
7
+ respond_to?("delegated_#{method_name}?") && send("delegated_#{method_name}?")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # reopen Module from ActiveSupport to redefine delegate method
4
+ class Module
5
+ alias __delegate delegate
6
+ def delegate(*methods, to: nil, prefix: nil, allow_nil: nil, private: nil)
7
+ if defined?(ActiveRecord::Base) && self < ActiveRecord::Base
8
+ methods.each do |method|
9
+ define_method("delegated_#{prefix}#{method}?") do
10
+ true
11
+ end
12
+ end
13
+ end
14
+ __delegate(*methods, to:, prefix:, allow_nil:, private:)
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "who_delegated/core_ext"
4
+ require "who_delegated/activerecord/base"
5
+
6
+ module WhoDelegated
7
+ class Railtie < ::Rails::Railtie
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WhoDelegated
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record/base"
4
+ require "active_support/core_ext/module/delegation"
5
+ require "who_delegated/railtie"
6
+ require "zeitwerk"
7
+ loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
8
+ loader.setup
9
+
10
+ module WhoDelegated # rubocop:todo Style/Documentation
11
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: who_delegated
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sampo Kuokkanen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ description: Was your Rails method delegated? Or not? That is the question. So find
28
+ out with this gem!
29
+ email:
30
+ - sampo.kuokkanen@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - lib/tasks/who_delegated_tasks.rake
39
+ - lib/who_delegated.rb
40
+ - lib/who_delegated/activerecord/base.rb
41
+ - lib/who_delegated/core_ext.rb
42
+ - lib/who_delegated/railtie.rb
43
+ - lib/who_delegated/version.rb
44
+ homepage: https://github.com/sampokuokkanen/who_delegated
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ homepage_uri: https://github.com/sampokuokkanen/who_delegated
49
+ source_code_uri: https://github.com/sampokuokkanen/who_delegated
50
+ changelog_uri: https://github.com/sampokuokkanen/who_delegated/blob/main/CHANGELOG.md
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 3.2.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.4.10
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: 'Rails: Find out if a method was delegated to an object.'
70
+ test_files: []