jeweler-utils 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 +147 -0
- data/Rakefile +27 -0
- data/lib/jeweler/audit_log.rb +52 -0
- data/lib/jeweler/languages.rb +149 -0
- data/lib/jeweler/service.rb +40 -0
- data/lib/jeweler/utils.rb +19 -0
- data/lib/jeweler/utils/core_ext/ActiveModelErrors.rb +12 -0
- data/lib/jeweler/utils/core_ext/Array.rb +17 -0
- data/lib/jeweler/utils/core_ext/BigDecimal.rb +37 -0
- data/lib/jeweler/utils/core_ext/Decimal.rb +30 -0
- data/lib/jeweler/utils/core_ext/Double.rb +30 -0
- data/lib/jeweler/utils/core_ext/Float.rb +36 -0
- data/lib/jeweler/utils/core_ext/Integer.rb +13 -0
- data/lib/jeweler/utils/core_ext/NilClass.rb +28 -0
- data/lib/jeweler/utils/core_ext/Object.rb +11 -0
- data/lib/jeweler/utils/core_ext/String.rb +28 -0
- data/lib/jeweler/utils/languages.rb +149 -0
- data/lib/jeweler/utils/railtie.rb +6 -0
- data/lib/jeweler/utils/version.rb +5 -0
- data/lib/tasks/jeweler/utils_tasks.rake +4 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1974f9550e708c7d132add3d623cbf9f73aa4b0a4a07f9251b3514e7b0ea964a
|
4
|
+
data.tar.gz: 2e8b9c973ee4984bf7413b81e21c6118edc6e760c97566a6b45f5de1134e2ebb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70edb8005912abcd0beb23405087d628762275e19d52f9de2f2540c628cf0afdc436c66ca1875058877472706f2f798e339dc71090559cbc1175dc0e21d69502
|
7
|
+
data.tar.gz: 0524203e61d1d901fde7588cc717ab016f02c7636573bd74c2d545dd694887eec4edeea03de89e1ecbaf961090f45de3a653bc2fc35df40258970b0aac71394f
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Vas Kaloidis
|
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,147 @@
|
|
1
|
+
# Jeweler::Utils
|
2
|
+
|
3
|
+
<p align="center">
|
4
|
+
<a href="http://staging.jewelercrm.io"><img width="400" src="https://raw.githubusercontent.com/vaskaloidis/jeweler/master/app/assets/images/jeweler-logo-full-alternate.png"></a>
|
5
|
+
|
6
|
+
[![CircleCI](https://circleci.com/gh/vaskaloidis/jeweler-utils.svg?style=svg)](https://circleci.com/gh/vaskaloidis/jeweler-utils)
|
7
|
+
[![Slack](https://img.shields.io/badge/discuss-Slack-brightgreen.svg)](https://bluehelmet.slack.com)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/github/vaskaloidis/jeweler/badge.svg?branch=master)](https://coveralls.io/github/vaskaloidis/jeweler?branch=master)
|
9
|
+
</p>
|
10
|
+
|
11
|
+
A utility package of various Core Extensions, helpers and Ruby Patterns we use for developing Jeweler.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
### Service Object Pattern
|
16
|
+
Used to build a Service Object.
|
17
|
+
|
18
|
+
- Returns `result` method which is set to the value of the result of the `Call` method
|
19
|
+
- Returns any errors in the `@errors` variable with initialized as an empty Array. Place error messages here.
|
20
|
+
- These can optionally be logged as a warning.
|
21
|
+
- Fatal errors can be stored in `@fatals` Array (initialized empty).
|
22
|
+
- This automatically enters the generic warning message `There was an error. Contact Support.` into `@errors`
|
23
|
+
- These automatically get logged as errors.
|
24
|
+
- Successful message is stored in `@result_message`, initialized as an empty String `''`
|
25
|
+
|
26
|
+
**Example:**
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class UpdateTask < Jeweler::Service
|
30
|
+
def initialize(task)
|
31
|
+
@task = task
|
32
|
+
end
|
33
|
+
|
34
|
+
def call
|
35
|
+
if task.update(hours: 4)
|
36
|
+
Note.create_event(task.sprint.project, 'task_deleted', 'Deleted: ' + task.description)
|
37
|
+
else
|
38
|
+
task.errors.full_messages.map { |e| fatals << 'Error Destroying Task: ' + e }
|
39
|
+
end
|
40
|
+
task
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
attr_reader :task
|
45
|
+
end
|
46
|
+
# Usage:
|
47
|
+
@service_object = DestroyTask.call(@task)
|
48
|
+
@service_object.errors # Combined array of fatals and errors. They are logged differently by Jeweler::Service though
|
49
|
+
@service_object.result # Task<id: 7, hours: 3...>
|
50
|
+
|
51
|
+
class ServiceObject1 < Jeweler::Service
|
52
|
+
def call
|
53
|
+
errors << 'error 1'
|
54
|
+
errors << 'error 2'
|
55
|
+
fatals << 'fatal 1'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
so = ServiceObject1.call
|
59
|
+
# ServiceObject1.errors = ['error 1', 'error 2', 'There was an error. Contact Support.']
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
### String
|
64
|
+
true? - returns true if the string is explicitly equal to 'true'
|
65
|
+
```ruby
|
66
|
+
'true'.true? # returns true ONLY
|
67
|
+
'truue'.true? # returns false
|
68
|
+
```
|
69
|
+
.to_b - converts the string 'true' and 'false' explicitly / respectively to TRUE / FALSE, otherwise it will throw an exception.
|
70
|
+
```ruby
|
71
|
+
'true'.to_b # TRUE
|
72
|
+
'false'.to_b # FALSE
|
73
|
+
'faalse'.to_b # Throws an Exception
|
74
|
+
```
|
75
|
+
|
76
|
+
### String, BigDecimal, Decimal, Float, Integer
|
77
|
+
|
78
|
+
.money - will convert this to a formatted USD money String, rounding it to 0 decimal places if it is a whole number
|
79
|
+
```ruby
|
80
|
+
(500.84).money # '$500.84'
|
81
|
+
(500.00).money # '$500'
|
82
|
+
```
|
83
|
+
|
84
|
+
### BigDecimal, Decimal, Float, Integer, Double
|
85
|
+
(Double does not have a rate)
|
86
|
+
|
87
|
+
.prettify - Rounds the number to 0 decimal places if it is a whole number anyway
|
88
|
+
```ruby
|
89
|
+
(500.00).prettify # 500
|
90
|
+
(500.87).prettify # 500.87
|
91
|
+
```
|
92
|
+
|
93
|
+
.rate - Converts a number to an hourly-rate in USD ($/hr) (String)
|
94
|
+
```ruby
|
95
|
+
(55.50) # '$55.50/hr'
|
96
|
+
```
|
97
|
+
|
98
|
+
.hours - Appends hours or hour to the end of a number, converts it to String
|
99
|
+
```ruby
|
100
|
+
(5).hours # '5 hrs'
|
101
|
+
(1).hours # '1 hr'
|
102
|
+
```
|
103
|
+
|
104
|
+
### NilClass
|
105
|
+
These, as well as the methods above are for displaying these numbers in the UI. I prefer these cleaner methods to the decorator pattern (in these few use-cases), because it is really really clean.
|
106
|
+
|
107
|
+
`(nil).prettify` - returns 0 (Integer)
|
108
|
+
`(nil).hours` - returns '0 hr.' (String)
|
109
|
+
`(nil).money` - returns '$0' (String)
|
110
|
+
`(nil).true?` - returns False (Boolean)
|
111
|
+
`(nil).to_b` - returns False (Boolean)
|
112
|
+
|
113
|
+
### Array
|
114
|
+
.log_errors(prefix_msg = nil) - Logs all of these errors, as errors, prefixed with the param (optionally)
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
sprint.errors.full_messages.log_errors('Error Saving Sprint')
|
118
|
+
# log.warn - Error Saving Sprint: the validation error while saving sprint
|
119
|
+
|
120
|
+
sprint.errors.full_messages.log_errors
|
121
|
+
# log.warn - the validation error while saving sprint
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
## Installation
|
127
|
+
Add this line to your application's Gemfile:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
gem 'jeweler-utils'
|
131
|
+
```
|
132
|
+
|
133
|
+
And then execute:
|
134
|
+
```bash
|
135
|
+
$ bundle
|
136
|
+
```
|
137
|
+
|
138
|
+
Or install it yourself as:
|
139
|
+
```bash
|
140
|
+
$ gem install jeweler-utils
|
141
|
+
```
|
142
|
+
|
143
|
+
## Contributing
|
144
|
+
Just submit a pull request with your modifications and I will take a look.
|
145
|
+
|
146
|
+
## License
|
147
|
+
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 = 'Jeweler::Utils'
|
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
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Namespace for the Jeweler Logger used for Auditing, Debugging Issues
|
2
|
+
# through logs, and Overall Error-rporting
|
3
|
+
module Logger
|
4
|
+
|
5
|
+
# Logger to be used ONLY during Controller logging because it accesses
|
6
|
+
# the @params [Hash] for @params[:action] and @params[:controller]
|
7
|
+
def action_log
|
8
|
+
rails_action = "#{ params[:controller] }##{ params[:action] }"
|
9
|
+
rails_params = params.except(:controller, :action)
|
10
|
+
|
11
|
+
# Search for the project ID
|
12
|
+
# @todo Replace with Strategory Pattern
|
13
|
+
project_id = case params
|
14
|
+
when key?('project') then
|
15
|
+
params[:project]
|
16
|
+
when key?('sprint') then
|
17
|
+
params[:sprint][:project_id]
|
18
|
+
when key?('task') then
|
19
|
+
Sprint.find(params[:task][:sprint_id]).project.id
|
20
|
+
when key?('note')
|
21
|
+
if defined? params[:note][:project_id]
|
22
|
+
params[:note][:project_id]
|
23
|
+
elsif defined? params[:note][:sprint_id]
|
24
|
+
Sprint.find(params[:task][:sprint_id]).project.id
|
25
|
+
end
|
26
|
+
when key?('payment') then
|
27
|
+
params[:payment][:project_id]
|
28
|
+
end
|
29
|
+
|
30
|
+
details = {
|
31
|
+
:logger => 'ActionLog',
|
32
|
+
:action => rails_action,
|
33
|
+
:user_id => current_user.id,
|
34
|
+
:params => rails_params,
|
35
|
+
:user_agent => request.user_agent
|
36
|
+
}
|
37
|
+
|
38
|
+
unless project_id.nil?
|
39
|
+
details[:project_id] = project_id
|
40
|
+
end
|
41
|
+
|
42
|
+
unless current_user.nil?
|
43
|
+
details[:current_user_id] = current_user.id
|
44
|
+
end
|
45
|
+
|
46
|
+
unless :ip_address.nil?
|
47
|
+
details[:ip_address] = ip_address
|
48
|
+
end
|
49
|
+
|
50
|
+
Rails.logger.info MultiJson.dump(details)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
module Jeweler
|
2
|
+
module Languages
|
3
|
+
def language_select
|
4
|
+
languages.map.with_index { |category, index| [pretty_language(category), index] }
|
5
|
+
end
|
6
|
+
|
7
|
+
def pretty_language(category)
|
8
|
+
pretty = {}
|
9
|
+
pretty['java ee'] = 'Java EE'
|
10
|
+
pretty['javafx'] = 'Java FX'
|
11
|
+
pretty['jquery'] = 'JQuery'
|
12
|
+
pretty['mips'] = 'MIPS'
|
13
|
+
pretty['c++'] = 'C++'
|
14
|
+
pretty['opengl'] = 'OpenGL'
|
15
|
+
pretty['sml'] = 'SML'
|
16
|
+
pretty['mongo db'] = 'Mongo DB'
|
17
|
+
pretty['yacc'] = 'YACC'
|
18
|
+
pretty['php'] = 'PHP'
|
19
|
+
pretty['mysql'] = 'MySQL'
|
20
|
+
pretty['node js'] = 'Node JS'
|
21
|
+
pretty['rails'] = 'Ruby on Rails'
|
22
|
+
pretty['mac osx'] = 'Mac OSX'
|
23
|
+
pretty['sass'] = 'SASS'
|
24
|
+
pretty['css'] = 'CSS'
|
25
|
+
pretty['maven mojo'] = 'Maven MOJO'
|
26
|
+
pretty['phpstorm'] = 'PhpStorm'
|
27
|
+
return pretty.fetch(category) if pretty.key?(category)
|
28
|
+
return category.titleize unless category.nil?
|
29
|
+
category
|
30
|
+
end
|
31
|
+
|
32
|
+
def languages
|
33
|
+
cat = []
|
34
|
+
cat << 'go'
|
35
|
+
cat << 'docker'
|
36
|
+
cat << 'css'
|
37
|
+
cat << 'apache'
|
38
|
+
cat << 'html'
|
39
|
+
cat << 'bootstrap'
|
40
|
+
cat << 'java ee'
|
41
|
+
cat << 'javafx'
|
42
|
+
cat << 'java'
|
43
|
+
cat << 'jquery'
|
44
|
+
cat << 'mips'
|
45
|
+
cat << 'c++'
|
46
|
+
cat << 'laravel'
|
47
|
+
cat << 'linux'
|
48
|
+
cat << 'opengl'
|
49
|
+
cat << 'sml'
|
50
|
+
cat << 'javascript'
|
51
|
+
cat << 'mongo db'
|
52
|
+
cat << 'c'
|
53
|
+
cat << 'yacc'
|
54
|
+
cat << 'circuit'
|
55
|
+
cat << 'php'
|
56
|
+
cat << 'mysql'
|
57
|
+
cat << 'node js'
|
58
|
+
cat << 'photoshop'
|
59
|
+
cat << 'rails'
|
60
|
+
cat << 'postgres'
|
61
|
+
cat << 'ruby'
|
62
|
+
cat << 'redis'
|
63
|
+
cat << 'mac osx'
|
64
|
+
cat << 'sass'
|
65
|
+
cat << 'ubuntu'
|
66
|
+
cat << 'bower'
|
67
|
+
cat << 'wordpress'
|
68
|
+
cat << 'css'
|
69
|
+
cat << 'python'
|
70
|
+
cat << 'maven'
|
71
|
+
cat << 'maven mojo'
|
72
|
+
cat << 'composer'
|
73
|
+
cat << 'mips'
|
74
|
+
cat << 'gulp'
|
75
|
+
cat << 'grunt'
|
76
|
+
cat << 'phpstorm'
|
77
|
+
cat << 'react'
|
78
|
+
cat << 'swift'
|
79
|
+
cat << 'wordpress'
|
80
|
+
cat << 'tomcat'
|
81
|
+
cat << 'travis'
|
82
|
+
cat.sort!
|
83
|
+
end
|
84
|
+
|
85
|
+
def devicon_language_icon_class(category)
|
86
|
+
case category
|
87
|
+
when 'heroku' then 'devicon-heroku-plain-wordmark colored'
|
88
|
+
when 'go' then 'devicon-go-line colored'
|
89
|
+
when 'github' then 'devicon-github-plain-wordmark colored'
|
90
|
+
when 'docker' then 'devicon-docker-plain-wordmark colored'
|
91
|
+
when 'css' then 'devicon-css3-plain colored'
|
92
|
+
when 'apache' then 'devicon-apache-plain-wordmark colored'
|
93
|
+
when 'html' then 'devicon-html5-plain-wordmark colored'
|
94
|
+
when 'bootstrap' then 'devicon-bootstrap-plain-wordmark colored'
|
95
|
+
when 'java ee'
|
96
|
+
when 'javafx'
|
97
|
+
when 'java' then 'devicon-java-plain-wordmark colored'
|
98
|
+
when 'jquery' then 'devicon-jquery-plain-wordmark colored'
|
99
|
+
when 'mips'
|
100
|
+
when 'c++' then 'devicon-cplusplus-plain colored'
|
101
|
+
when 'laravel' then 'devicon-laravel-plain-wordmark colored'
|
102
|
+
when 'linux' then 'devicon-linux-plain colored'
|
103
|
+
when 'opengl'
|
104
|
+
when 'sml'
|
105
|
+
when 'javascript' then 'devicon-javascript-plain colored'
|
106
|
+
when 'mongo db' then 'devicon-mongodb-plain-wordmark colored'
|
107
|
+
when 'c' then 'devicon-c-line-wordmark colored'
|
108
|
+
when 'yacc'
|
109
|
+
when 'circuit'
|
110
|
+
when 'php' then 'devicon-php-plain colored'
|
111
|
+
when 'mysql' then 'devicon-mysql-plain-wordmark colored'
|
112
|
+
when 'node js' then 'devicon-nodejs-plain colored'
|
113
|
+
when 'photoshop' then 'devicon-photoshop-line colored'
|
114
|
+
when 'rails' then 'devicon-rails-plain-wordmark colored'
|
115
|
+
when 'postgres' then 'devicon-postgresql-plain-wordmark colored'
|
116
|
+
when 'ruby' then 'devicon-ruby-plain-wordmark colored'
|
117
|
+
when 'redis' then 'devicon-redis-plain-wordmark colored'
|
118
|
+
when 'mac osx' then 'devicon-apple-original colored'
|
119
|
+
when 'sass' then 'devicon-sass-original colored'
|
120
|
+
when 'ubuntu' then 'devicon-ubuntu-plain-wordmark colored'
|
121
|
+
when 'bower' then 'devicon-bower-plain-wordmark colored'
|
122
|
+
when 'wordpress' then 'devicon-Bluehelmet-plain-wordmark colored'
|
123
|
+
when 'css'
|
124
|
+
when 'hosted' then 'devicon-docker-plain-wordmark colored'
|
125
|
+
when 'python' then 'devicon-python-plain-wordmark colored'
|
126
|
+
when 'maven'
|
127
|
+
when 'maven mojo'
|
128
|
+
when 'composer'
|
129
|
+
when 'mips'
|
130
|
+
when 'gulp' then 'devicon-gulp-plain colored'
|
131
|
+
when 'grunt' then 'devicon-grunt-line-wordmark colored'
|
132
|
+
when 'phpstorm' then 'devicon-phpstorm-plain-wordmark colored'
|
133
|
+
when 'react' then 'devicon-react-original-wordmark colored'
|
134
|
+
when 'swift' then 'devicon-swift-plain-wordmark colored'
|
135
|
+
when 'wordpress' then 'devicon-wordpress-plain-wordmark colored'
|
136
|
+
when 'tomcat' then 'devicon-tomcat-line-wordmark colored'
|
137
|
+
when 'redis' then 'devicon-redis-plain-wordmark colored'
|
138
|
+
when 'travis' then 'devicon-travis-plain-wordmark colored'
|
139
|
+
else ''
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def build_icon(language)
|
144
|
+
return '' if language.nil?
|
145
|
+
language = languages.at(language) if language.is_a? Numeric
|
146
|
+
'<i class="devicon ' + devicon_language_icon_class(language) + '"></i>'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# TODO: Add RDocs
|
2
|
+
# TODO: Specify the Rescue From Catching ALL Errors. Only Specific ones, then handle them
|
3
|
+
# TODO: Implement various tools from ActiveModel Callbacks like serialization etc... http://www.thegreatcodeadventure.com/smarter-rails-services-with-active-record-modules/
|
4
|
+
module Jeweler
|
5
|
+
|
6
|
+
class Service
|
7
|
+
attr_accessor :result, :errors, :fatals, :result, :result_message
|
8
|
+
|
9
|
+
def self.call(*args)
|
10
|
+
|
11
|
+
new(*args).tap do |service|
|
12
|
+
service.instance_variable_set('@errors', Array.new)
|
13
|
+
service.instance_variable_set('@fatals', Array.new)
|
14
|
+
service.instance_variable_set('@result_message', '')
|
15
|
+
|
16
|
+
service.instance_variable_set("@result", service.call)
|
17
|
+
|
18
|
+
tapped_errors = service.instance_variable_get('@errors')
|
19
|
+
tapped_fatals = service.instance_variable_get('@fatals')
|
20
|
+
|
21
|
+
first_fatal = true
|
22
|
+
tapped_fatals.each do |fatal|
|
23
|
+
Rails.logger.error 'ServiceObject Fatal Error: ' + fatal
|
24
|
+
if first_fatal
|
25
|
+
tapped_errors << 'There was an error. Contact Support.'
|
26
|
+
first_fatal = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
service.instance_variable_set('@errors', tapped_errors)
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def call
|
36
|
+
raise NotImplementedError
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'jeweler/utils/railtie'
|
2
|
+
require 'jeweler/utils/core_ext/Object'
|
3
|
+
require 'jeweler/utils/core_ext/String'
|
4
|
+
require 'jeweler/utils/core_ext/BigDecimal'
|
5
|
+
require 'jeweler/utils/core_ext/Decimal'
|
6
|
+
require 'jeweler/utils/core_ext/Double'
|
7
|
+
require 'jeweler/utils/core_ext/Float'
|
8
|
+
require 'jeweler/utils/core_ext/Integer'
|
9
|
+
require 'jeweler/utils/core_ext/NilClass'
|
10
|
+
require 'jeweler/utils/core_ext/Array'
|
11
|
+
require 'jeweler/utils/core_ext/ActiveModelErrors'
|
12
|
+
|
13
|
+
require 'jeweler/service'
|
14
|
+
require 'jeweler/languages'
|
15
|
+
|
16
|
+
module Jeweler
|
17
|
+
module Utils
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Array
|
2
|
+
# Logs all of these errors, as errors, prefixed with the param (optionally)
|
3
|
+
def log_errors(prefix_msg = nil)
|
4
|
+
each do |e|
|
5
|
+
if prefix_msg.nil?
|
6
|
+
Rails.logger.error e
|
7
|
+
else
|
8
|
+
Rails.logger.error prefix_msg + ': ' + e
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
def build_errors
|
13
|
+
each do |e|
|
14
|
+
@errors << e
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class BigDecimal
|
2
|
+
def prettify
|
3
|
+
if self.nil?
|
4
|
+
return 0
|
5
|
+
else
|
6
|
+
if self.to_i == self
|
7
|
+
return self.to_f.round(0)
|
8
|
+
else
|
9
|
+
return self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def rate
|
15
|
+
result = self.prettify.to_s
|
16
|
+
result = '$' + result + ' /hr'
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
def hours
|
21
|
+
result = self.prettify
|
22
|
+
if result == 1
|
23
|
+
result = result.to_s + ' hr'
|
24
|
+
else
|
25
|
+
result = result.to_s + ' hrs'
|
26
|
+
end
|
27
|
+
return result
|
28
|
+
end
|
29
|
+
|
30
|
+
def money
|
31
|
+
require 'action_view/helpers/number_helper'
|
32
|
+
result = self.prettify
|
33
|
+
result = ActionView::Base.new.number_to_currency(result).to_s
|
34
|
+
return result
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Decimal
|
2
|
+
def prettify
|
3
|
+
if self.nil?
|
4
|
+
return 0
|
5
|
+
else
|
6
|
+
if self.to_i == self
|
7
|
+
return self.to_i
|
8
|
+
else
|
9
|
+
return self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def hours
|
15
|
+
result = self.prettify
|
16
|
+
if result == 1
|
17
|
+
result = result + ' hr'
|
18
|
+
else
|
19
|
+
result = result + 'hrs'
|
20
|
+
end
|
21
|
+
return result
|
22
|
+
end
|
23
|
+
|
24
|
+
def money
|
25
|
+
require 'action_view'
|
26
|
+
result = self.prettify
|
27
|
+
result = ActionView::Base.new.number_to_currency(result).to_s
|
28
|
+
return result
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Double
|
2
|
+
def prettify
|
3
|
+
if self.nil?
|
4
|
+
return 0
|
5
|
+
else
|
6
|
+
if self.round(2) == self
|
7
|
+
return self.round(2)
|
8
|
+
else
|
9
|
+
return self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def hours
|
15
|
+
result = self.prettify
|
16
|
+
if result == 1
|
17
|
+
result = result + ' hr.'
|
18
|
+
else
|
19
|
+
result = result + 'hrs.'
|
20
|
+
end
|
21
|
+
return result
|
22
|
+
end
|
23
|
+
|
24
|
+
def money
|
25
|
+
require 'action_view'
|
26
|
+
result = self.prettify
|
27
|
+
result = ActionView::Base.new.number_to_currency(result).to_s
|
28
|
+
return result
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Float
|
2
|
+
def prettify
|
3
|
+
if self.nil?
|
4
|
+
return 0
|
5
|
+
else
|
6
|
+
if self.to_i == self
|
7
|
+
return self.round(0)
|
8
|
+
else
|
9
|
+
return self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def hours
|
15
|
+
result = self.prettify
|
16
|
+
if result == 1
|
17
|
+
result = result.to_s + ' hr.'
|
18
|
+
else
|
19
|
+
result = result.to_s + ' hrs.'
|
20
|
+
end
|
21
|
+
return result
|
22
|
+
end
|
23
|
+
|
24
|
+
def rate
|
25
|
+
result = self.prettify.to_s
|
26
|
+
result = '$' + result + ' /hr'
|
27
|
+
return result
|
28
|
+
end
|
29
|
+
|
30
|
+
def money
|
31
|
+
require 'action_view'
|
32
|
+
result = self.prettify
|
33
|
+
result = ActionView::Base.new.number_to_currency(result).to_s
|
34
|
+
return result
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# These, as well as the methods above are for displaying these numbers in the UI. I prefer these cleaner methods to the decorator pattern (in these few use-cases), because it is really really clean.
|
2
|
+
class NilClass
|
3
|
+
|
4
|
+
# Returns 0
|
5
|
+
def prettify
|
6
|
+
return 0
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns '0 hr.'
|
10
|
+
def hours
|
11
|
+
return '0 hr.'
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns '$0'
|
15
|
+
def money
|
16
|
+
return '$0'
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns False
|
20
|
+
def true?
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns False
|
25
|
+
def to_b
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Useful String methods for Jeweler: .true?, .to_b and .money
|
2
|
+
class String
|
3
|
+
# Returns true if the string is equal to 'true'
|
4
|
+
def true?
|
5
|
+
to_s == 'true'
|
6
|
+
end
|
7
|
+
|
8
|
+
# Returns true if String is explicitly equal to 'true'
|
9
|
+
# Returns false if String is explicitly equal to 'false'
|
10
|
+
# raise ArgumentError if any other String is evaluated
|
11
|
+
def to_b
|
12
|
+
if to_s == 'true'
|
13
|
+
true
|
14
|
+
elsif to_s == 'false'
|
15
|
+
false
|
16
|
+
else
|
17
|
+
# raise SyntaxError
|
18
|
+
raise ArgumentError 'String being evaluated by to_b can only be equal to True or False'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Parses a number by converting it to a Double, formatting
|
23
|
+
# it as money, and then converting it back to String
|
24
|
+
# Example: $32.50 (String)
|
25
|
+
def money
|
26
|
+
to_d.money.to_s
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
module Jeweler
|
2
|
+
module Languages
|
3
|
+
def language_select
|
4
|
+
languages.map.with_index { |category, index| [pretty_language(category), index] }
|
5
|
+
end
|
6
|
+
|
7
|
+
def pretty_language(category)
|
8
|
+
pretty = {}
|
9
|
+
pretty['java ee'] = 'Java EE'
|
10
|
+
pretty['javafx'] = 'Java FX'
|
11
|
+
pretty['jquery'] = 'JQuery'
|
12
|
+
pretty['mips'] = 'MIPS'
|
13
|
+
pretty['c++'] = 'C++'
|
14
|
+
pretty['opengl'] = 'OpenGL'
|
15
|
+
pretty['sml'] = 'SML'
|
16
|
+
pretty['mongo db'] = 'Mongo DB'
|
17
|
+
pretty['yacc'] = 'YACC'
|
18
|
+
pretty['php'] = 'PHP'
|
19
|
+
pretty['mysql'] = 'MySQL'
|
20
|
+
pretty['node js'] = 'Node JS'
|
21
|
+
pretty['rails'] = 'Ruby on Rails'
|
22
|
+
pretty['mac osx'] = 'Mac OSX'
|
23
|
+
pretty['sass'] = 'SASS'
|
24
|
+
pretty['css'] = 'CSS'
|
25
|
+
pretty['maven mojo'] = 'Maven MOJO'
|
26
|
+
pretty['phpstorm'] = 'PhpStorm'
|
27
|
+
return pretty.fetch(category) if pretty.key?(category)
|
28
|
+
return category.titleize unless category.nil?
|
29
|
+
category
|
30
|
+
end
|
31
|
+
|
32
|
+
def languages
|
33
|
+
cat = []
|
34
|
+
cat << 'go'
|
35
|
+
cat << 'docker'
|
36
|
+
cat << 'css'
|
37
|
+
cat << 'apache'
|
38
|
+
cat << 'html'
|
39
|
+
cat << 'bootstrap'
|
40
|
+
cat << 'java ee'
|
41
|
+
cat << 'javafx'
|
42
|
+
cat << 'java'
|
43
|
+
cat << 'jquery'
|
44
|
+
cat << 'mips'
|
45
|
+
cat << 'c++'
|
46
|
+
cat << 'laravel'
|
47
|
+
cat << 'linux'
|
48
|
+
cat << 'opengl'
|
49
|
+
cat << 'sml'
|
50
|
+
cat << 'javascript'
|
51
|
+
cat << 'mongo db'
|
52
|
+
cat << 'c'
|
53
|
+
cat << 'yacc'
|
54
|
+
cat << 'circuit'
|
55
|
+
cat << 'php'
|
56
|
+
cat << 'mysql'
|
57
|
+
cat << 'node js'
|
58
|
+
cat << 'photoshop'
|
59
|
+
cat << 'rails'
|
60
|
+
cat << 'postgres'
|
61
|
+
cat << 'ruby'
|
62
|
+
cat << 'redis'
|
63
|
+
cat << 'mac osx'
|
64
|
+
cat << 'sass'
|
65
|
+
cat << 'ubuntu'
|
66
|
+
cat << 'bower'
|
67
|
+
cat << 'wordpress'
|
68
|
+
cat << 'css'
|
69
|
+
cat << 'python'
|
70
|
+
cat << 'maven'
|
71
|
+
cat << 'maven mojo'
|
72
|
+
cat << 'composer'
|
73
|
+
cat << 'mips'
|
74
|
+
cat << 'gulp'
|
75
|
+
cat << 'grunt'
|
76
|
+
cat << 'phpstorm'
|
77
|
+
cat << 'react'
|
78
|
+
cat << 'swift'
|
79
|
+
cat << 'wordpress'
|
80
|
+
cat << 'tomcat'
|
81
|
+
cat << 'travis'
|
82
|
+
cat.sort!
|
83
|
+
end
|
84
|
+
|
85
|
+
def devicon_language_icon_class(category)
|
86
|
+
case category
|
87
|
+
when 'heroku' then 'devicon-heroku-plain-wordmark colored'
|
88
|
+
when 'go' then 'devicon-go-line colored'
|
89
|
+
when 'github' then 'devicon-github-plain-wordmark colored'
|
90
|
+
when 'docker' then 'devicon-docker-plain-wordmark colored'
|
91
|
+
when 'css' then 'devicon-css3-plain colored'
|
92
|
+
when 'apache' then 'devicon-apache-plain-wordmark colored'
|
93
|
+
when 'html' then 'devicon-html5-plain-wordmark colored'
|
94
|
+
when 'bootstrap' then 'devicon-bootstrap-plain-wordmark colored'
|
95
|
+
when 'java ee'
|
96
|
+
when 'javafx'
|
97
|
+
when 'java' then 'devicon-java-plain-wordmark colored'
|
98
|
+
when 'jquery' then 'devicon-jquery-plain-wordmark colored'
|
99
|
+
when 'mips'
|
100
|
+
when 'c++' then 'devicon-cplusplus-plain colored'
|
101
|
+
when 'laravel' then 'devicon-laravel-plain-wordmark colored'
|
102
|
+
when 'linux' then 'devicon-linux-plain colored'
|
103
|
+
when 'opengl'
|
104
|
+
when 'sml'
|
105
|
+
when 'javascript' then 'devicon-javascript-plain colored'
|
106
|
+
when 'mongo db' then 'devicon-mongodb-plain-wordmark colored'
|
107
|
+
when 'c' then 'devicon-c-line-wordmark colored'
|
108
|
+
when 'yacc'
|
109
|
+
when 'circuit'
|
110
|
+
when 'php' then 'devicon-php-plain colored'
|
111
|
+
when 'mysql' then 'devicon-mysql-plain-wordmark colored'
|
112
|
+
when 'node js' then 'devicon-nodejs-plain colored'
|
113
|
+
when 'photoshop' then 'devicon-photoshop-line colored'
|
114
|
+
when 'rails' then 'devicon-rails-plain-wordmark colored'
|
115
|
+
when 'postgres' then 'devicon-postgresql-plain-wordmark colored'
|
116
|
+
when 'ruby' then 'devicon-ruby-plain-wordmark colored'
|
117
|
+
when 'redis' then 'devicon-redis-plain-wordmark colored'
|
118
|
+
when 'mac osx' then 'devicon-apple-original colored'
|
119
|
+
when 'sass' then 'devicon-sass-original colored'
|
120
|
+
when 'ubuntu' then 'devicon-ubuntu-plain-wordmark colored'
|
121
|
+
when 'bower' then 'devicon-bower-plain-wordmark colored'
|
122
|
+
when 'wordpress' then 'devicon-Bluehelmet-plain-wordmark colored'
|
123
|
+
when 'css'
|
124
|
+
when 'hosted' then 'devicon-docker-plain-wordmark colored'
|
125
|
+
when 'python' then 'devicon-python-plain-wordmark colored'
|
126
|
+
when 'maven'
|
127
|
+
when 'maven mojo'
|
128
|
+
when 'composer'
|
129
|
+
when 'mips'
|
130
|
+
when 'gulp' then 'devicon-gulp-plain colored'
|
131
|
+
when 'grunt' then 'devicon-grunt-line-wordmark colored'
|
132
|
+
when 'phpstorm' then 'devicon-phpstorm-plain-wordmark colored'
|
133
|
+
when 'react' then 'devicon-react-original-wordmark colored'
|
134
|
+
when 'swift' then 'devicon-swift-plain-wordmark colored'
|
135
|
+
when 'wordpress' then 'devicon-wordpress-plain-wordmark colored'
|
136
|
+
when 'tomcat' then 'devicon-tomcat-line-wordmark colored'
|
137
|
+
when 'redis' then 'devicon-redis-plain-wordmark colored'
|
138
|
+
when 'travis' then 'devicon-travis-plain-wordmark colored'
|
139
|
+
else ''
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def build_icon(language)
|
144
|
+
return '' if language.nil?
|
145
|
+
language = languages.at(language) if language.is_a? Numeric
|
146
|
+
'<i class="devicon ' + devicon_language_icon_class(language) + '"></i>'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jeweler-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vas Kaloidis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sqlite3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.2.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.2.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: actionpack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.2.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.2.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: virtus
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.2.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.2.0
|
83
|
+
description: Various ActiveRecord, Object, String and Number Core-Extensions plus
|
84
|
+
Service Object Pattern.
|
85
|
+
email:
|
86
|
+
- vas.kaloidis@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- MIT-LICENSE
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/jeweler/audit_log.rb
|
95
|
+
- lib/jeweler/languages.rb
|
96
|
+
- lib/jeweler/service.rb
|
97
|
+
- lib/jeweler/utils.rb
|
98
|
+
- lib/jeweler/utils/core_ext/ActiveModelErrors.rb
|
99
|
+
- lib/jeweler/utils/core_ext/Array.rb
|
100
|
+
- lib/jeweler/utils/core_ext/BigDecimal.rb
|
101
|
+
- lib/jeweler/utils/core_ext/Decimal.rb
|
102
|
+
- lib/jeweler/utils/core_ext/Double.rb
|
103
|
+
- lib/jeweler/utils/core_ext/Float.rb
|
104
|
+
- lib/jeweler/utils/core_ext/Integer.rb
|
105
|
+
- lib/jeweler/utils/core_ext/NilClass.rb
|
106
|
+
- lib/jeweler/utils/core_ext/Object.rb
|
107
|
+
- lib/jeweler/utils/core_ext/String.rb
|
108
|
+
- lib/jeweler/utils/languages.rb
|
109
|
+
- lib/jeweler/utils/railtie.rb
|
110
|
+
- lib/jeweler/utils/version.rb
|
111
|
+
- lib/tasks/jeweler/utils_tasks.rake
|
112
|
+
homepage: http://www.bluehelmet.software
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.7.6
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Helper and Utility methods for Jeweler, Jeweler::Utils.
|
136
|
+
test_files: []
|