easy_goes_it 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +59 -0
- data/Rakefile +27 -0
- data/lib/easy_goes_it.rb +93 -0
- data/lib/easy_goes_it/railtie.rb +4 -0
- data/lib/easy_goes_it/version.rb +3 -0
- data/lib/helpers/easy_goes_it.rb +3 -0
- data/lib/tasks/easy_goes_it_tasks.rake +4 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 84bd0bfa0a6c8831b6d9b63cec3b9f65cf9c8bb4
|
4
|
+
data.tar.gz: 9c7f6f1668d7df8f69decb42434fa0606748f896
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2eacfa481e36d69b6b95a0d5f48d4f9522498054344eb2698c71ed2e12b762c456f857eb7ebd0ed963e0c67f3e453fb8651f56498516406ca3e1ebdcdf3be74
|
7
|
+
data.tar.gz: 181322c22c6e5d024a6d79b10d05d6d8e35e5a683070c04b4aab7527d51db9e08d4938291eb2de040d0f2280928c1af0cd557b5656c5a5bcd8c6a1615573b95f
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 Kevin J. Storberg
|
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,59 @@
|
|
1
|
+
# Name
|
2
|
+
EasyGoesIt
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
# Description
|
7
|
+
EasyGoesIt is simply a collection of methods which make life a little bit easier.
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
# Usage
|
12
|
+
A collection of code for the lazy in all of us.
|
13
|
+
|
14
|
+
## Models
|
15
|
+
- methods for the models
|
16
|
+
|
17
|
+
## Views
|
18
|
+
- methods for the views
|
19
|
+
|
20
|
+
## Controllers
|
21
|
+
- methods for the controllers
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
# Installation
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'easy_goes_it'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
```bash
|
34
|
+
$ bundle
|
35
|
+
```
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
```bash
|
39
|
+
$ gem install easy_goes_it
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
# Authors
|
44
|
+
- Kevin J. Storberg, Ooftypop Inc.
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
# Contributing
|
49
|
+
We welcome collaboration on all of our open source projects.
|
50
|
+
|
51
|
+
When contributing to EasyGoesIt, we ask that you:
|
52
|
+
- notify us of your intended contribution so we may provide feedback
|
53
|
+
- make a PR on Github with a short description of your changes
|
54
|
+
- update any relevant documentation
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
# License
|
59
|
+
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
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'EasyGoesIt'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
data/lib/easy_goes_it.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require "easy_goes_it/railtie"
|
2
|
+
|
3
|
+
module EasyGoesIt
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
private
|
6
|
+
|
7
|
+
# ============================================================================
|
8
|
+
# Queries ====================================================================
|
9
|
+
# ============================================================================
|
10
|
+
# SimulationResult.generate_date_ranges(SimulationResult.all, :status_change_date)
|
11
|
+
# => [date_range 1, date_range 2, date_range 3 ... date_range n ... date_range N]
|
12
|
+
included do
|
13
|
+
def self.generate_date_ranges(objects, attribute, increment)
|
14
|
+
return [] if objects.empty? || attribute.blank? || increment.blank?
|
15
|
+
|
16
|
+
lower_bound = objects.minimum(attribute).strftime("%Y-%m-1").to_date
|
17
|
+
upper_bound = objects.maximum(attribute).strftime("%Y-%m-1").to_date
|
18
|
+
|
19
|
+
date = lower_bound
|
20
|
+
date_ranges = []
|
21
|
+
index = 0
|
22
|
+
|
23
|
+
while date <= upper_bound
|
24
|
+
next_month = date + 1.send(increment.to_sym)
|
25
|
+
date_ranges[index] = date..next_month
|
26
|
+
|
27
|
+
index = index + 1
|
28
|
+
date = next_month
|
29
|
+
end
|
30
|
+
|
31
|
+
return date_ranges
|
32
|
+
end
|
33
|
+
|
34
|
+
# For searching by date range on multiple attributes at once (i.e. attribute OR attribute)
|
35
|
+
# First argument is date range and second argument is the array of attributes to be searched
|
36
|
+
def self.date_range_between(range, attributes)
|
37
|
+
return if range.blank? || attributes.blank?
|
38
|
+
set = self.where(attributes.first => range)
|
39
|
+
attributes.each do |attribute|
|
40
|
+
next if attribute == attributes.first
|
41
|
+
set = set.or(self.where(attribute => range))
|
42
|
+
end
|
43
|
+
|
44
|
+
return set
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# ============================================================================
|
49
|
+
# Formatters =================================================================
|
50
|
+
# ============================================================================
|
51
|
+
# Motivation.new(name: 'Hello World').dynamic_name => 'Hello World'
|
52
|
+
def dynamic_name # Motivation.new.dynamic_name => 'New Motivation'
|
53
|
+
class_name = self.class.table_name.to_sym
|
54
|
+
attributes = [:banner, :display_name, :head, :heading, :headline, :label, :title, :name]
|
55
|
+
attribute = attributes.find {|attribute| ActiveRecord::Base.connection.column_exists?(class_name, attribute) }
|
56
|
+
|
57
|
+
ActiveRecord::Base.connection.close if ActiveRecord::Base.connection
|
58
|
+
|
59
|
+
if self.send(attribute).present?
|
60
|
+
self.send(attribute)
|
61
|
+
else
|
62
|
+
self.new_record? ? "New #{self.class.name.underscore.humanize}" : self.send(attribute)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def downcase_attributes(*args)
|
67
|
+
args.each do |arg|
|
68
|
+
next if arg.blank? || self.send(arg.to_sym).blank?
|
69
|
+
self.assign_attributes(arg.to_sym => self.send(arg.to_sym).downcase)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# ============================================================================
|
74
|
+
# System Admin ===============================================================
|
75
|
+
# ============================================================================
|
76
|
+
def self.in_development?
|
77
|
+
Rails.env.development?
|
78
|
+
end
|
79
|
+
|
80
|
+
def in_development?
|
81
|
+
Rails.env.development?
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.in_production?
|
85
|
+
Rails.env.production?
|
86
|
+
end
|
87
|
+
|
88
|
+
def in_production?
|
89
|
+
Rails.env.production?
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
ActiveRecord::Base.send(:include, EasyGoesIt)
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_goes_it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin J. Storberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-20 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: 5.2.2
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.2.2.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.2.2
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.2.2.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sqlite3
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: A collection of code for the lazy in all of us.
|
48
|
+
email:
|
49
|
+
- kevin@ooftypop.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/easy_goes_it.rb
|
58
|
+
- lib/easy_goes_it/railtie.rb
|
59
|
+
- lib/easy_goes_it/version.rb
|
60
|
+
- lib/helpers/easy_goes_it.rb
|
61
|
+
- lib/tasks/easy_goes_it_tasks.rake
|
62
|
+
homepage: https://github.com/ooftypop/easy_goes_it
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.6.10
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: A collection of code for the lazy in all of us.
|
86
|
+
test_files: []
|