boolean_scope 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d1d19e4de7f2cb1154b10ec36d107a6f067de13938a65dcdb5cbc4d76f07464
4
+ data.tar.gz: 414b43b39d57b7c6821c5e3da47accef85d0c1710088b4094fba072c933239ea
5
+ SHA512:
6
+ metadata.gz: f7a2cef10a479ac0d28aaf3c392a86e91fbd6909b70911fb9145e88a662f7aa3ca0faee0f9a72d10ed71a050725e8774a3099a92821e4cc27116c5b3fbf9b439
7
+ data.tar.gz: 59a36013b05e128e5a7a16ca43db19491a64c7290649bdf5a0ba68adc6bf2f5d062d1669766e8178346c9cf3275a1adaef2b0211fff7b77071b42fe4569f952d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in boolean_scope.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rubocop"
8
+ gem "solargraph"
@@ -0,0 +1,36 @@
1
+ # BooleanScope
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/boolean_scope`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'boolean_scope'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install boolean_scope
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dashkb/boolean_scope.
36
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "boolean_scope"
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(__FILE__)
@@ -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,16 @@
1
+ require_relative 'lib/boolean_scope/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "boolean_scope"
5
+ spec.version = BooleanScope::VERSION
6
+ spec.authors = ["Kyle Brett"]
7
+ spec.email = ["kyle@kylebrett.com"]
8
+
9
+ spec.summary = %q{Simple boolean scopes for ActiveRecord}
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11
+
12
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
13
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ end
15
+ spec.require_paths = ["lib"]
16
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'boolean_scope/version'
4
+
5
+ module BooleanScope #:nodoc:
6
+ extend ActiveSupport::Concern
7
+
8
+ class_methods do
9
+ def has_boolean_scope(*args)
10
+ opts = args.extract_options!
11
+
12
+ name, alt_name = args
13
+ column = opts[:column] || name
14
+ alt_name ||= :"not_#{name}"
15
+
16
+ define_method :"#{alt_name}?" do
17
+ send(column).blank?
18
+ end
19
+
20
+ if name != column
21
+ define_method :"#{name}?" do
22
+ send(column).present?
23
+ end
24
+ end
25
+
26
+ define_method :"#{name}=" do |val|
27
+ if [false, 'false'].include?(val)
28
+ super nil
29
+ else
30
+ super val
31
+ end
32
+ end
33
+
34
+ (class << self; self end).class_eval do
35
+ define_method name do
36
+ create_with(column => true).where %(
37
+ #{column} is not null
38
+ )
39
+ end
40
+
41
+ define_method alt_name do
42
+ where("#{column} is null")
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module BooleanScope
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boolean_scope
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Brett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - kyle@kylebrett.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - README.md
23
+ - Rakefile
24
+ - bin/console
25
+ - bin/setup
26
+ - boolean_scope.gemspec
27
+ - lib/boolean_scope.rb
28
+ - lib/boolean_scope/version.rb
29
+ homepage:
30
+ licenses: []
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.3.0
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.1.2
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Simple boolean scopes for ActiveRecord
51
+ test_files: []