activerecord_squared 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7368d7970a209d6b71cfa873affb3008ffca8021ad09fe3562876680c2cba15c
4
+ data.tar.gz: 7f17f52c409bacc250b09b42a4352712555b5aa5bd67231a9919587a480d8911
5
+ SHA512:
6
+ metadata.gz: 317f033959b5f586b75eb7a72bbe4af848fa8af652aeba80e2f3c4f26e5ec28ec8bd8278e39c2f0b016ce07274bde3e57f10dcb134c9e53b042063252e967d4c
7
+ data.tar.gz: f86d6456c4d689ed33497ba4364e1b25a92e5dad692e5d9fa80fd0a613a631b18478ef4ea371b010c4c3924d469d939e0e1fd962ae4d18b661c259a3bff5e672
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # ActiverecordSquared
2
+ Tired of typing ```SomeModel.find_by(id: 12)```? Yeah man me too.
3
+
4
+ Even ```SomeModel.find(12)``` still a bit too long?
5
+
6
+ Wonder why you have to have 2 different methods for find and find_by, when it ought to be reasonably obvious which is called purely by the argument??
7
+
8
+ Man do we have the solution for you. Introducing...ActiveRecord...squared!...the gem that adds a class-level square bracket method to ActiveRecord objects!
9
+
10
+ What does it do? Now you can replace that with ```SomeModel[12]```. Also, you can, with zero added effort say: ```SomeModel[email_address: 'man_email_sucks@example.com']```! Revolutionary! You can do ```SomeModel[params[:id].present?``` - and ... even if the param is nil, it doesn't error out. You can even do a ```SomeModel[]``` to get everything. Stuff you could already do, but ... esier and more elegant! Great!
11
+
12
+ ## Installation
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'activerecord_squared'
17
+ ```
18
+
19
+ And then execute:
20
+ ```bash
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+ ```bash
26
+ $ gem install activerecord_squared
27
+ ```
28
+
29
+ ## Usage
30
+ There are 2 main modes for this, and they are based on what is passed in the bracket:
31
+
32
+ Singular Identifier
33
+ : Either a string or integer (most likely) - similar to calling ```SomeModel.where()```. This is the default mode. One of the more interesting options here is the ability to call ```SomeModel[params[:id]]``` - with nil as the id, and get ... nil. Not an error, like you'd get with find, but nil.
34
+
35
+ Finder Hash
36
+ : Similar to calling ```SomeModel.find_by()```.
37
+
38
+ Of course, as this is ActiveRecord, they all return activerecord queries, not actual objects...and can thus be chained appropriately (though ... it's not terribly recommended - this is a shorthand - if you're gonna chain stuff, you probably want to be explicit).
39
+
40
+ ## License
41
+ 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,13 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
+ task default: :test
@@ -0,0 +1,7 @@
1
+ require "activerecord_squared/version"
2
+ require "activerecord_squared/railtie"
3
+ require 'activerecord_squared/activerecord_ext'
4
+
5
+ module ActiverecordSquared
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,15 @@
1
+ module ActiveRecord
2
+ class Base
3
+ def self.[](input)
4
+ case input
5
+ when nil
6
+ # Specifically enables ```SomeModel[nil]``` to not error out.
7
+ return nil
8
+ when ::Hash
9
+ return self.where(input)
10
+ else
11
+ return self.find(input)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ module ActiverecordSquared
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module ActiverecordSquared
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord_squared
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Schultz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-01 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: 4.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.3
27
+ description: Adds a [] method at the class level for activerecord objects.
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - Rakefile
35
+ - lib/activerecord_squared.rb
36
+ - lib/activerecord_squared/activerecord_ext.rb
37
+ - lib/activerecord_squared/railtie.rb
38
+ - lib/activerecord_squared/version.rb
39
+ homepage: https://github.com/MatthewSchultz/activerecord_squared
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://github.com/MatthewSchultz/activerecord_squared
44
+ source_code_uri: https://github.com/MatthewSchultz/activerecord_squared
45
+ changelog_uri: https://github.com/MatthewSchultz/activerecord_squared/blob/main/CHANGELOG.md
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.3
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.1.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A shortcut for activerecord find.
65
+ test_files: []