human_attributes 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +104 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.rubocop.yml +65 -594
- data/.ruby-version +1 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +216 -144
- data/Guardfile +4 -4
- data/README.md +37 -17
- data/Rakefile +1 -1
- data/human_attributes.gemspec +11 -7
- data/lib/human_attributes/extension.rb +5 -3
- data/lib/human_attributes/formatters/base.rb +1 -0
- data/lib/human_attributes/formatters/enumerize.rb +1 -0
- data/lib/human_attributes/formatters_builder.rb +1 -0
- data/lib/human_attributes/version.rb +1 -1
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +3 -3
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/{assets/javascripts → javascript/packs}/application.js +3 -1
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/purchase.rb +1 -1
- data/spec/dummy/app/views/layouts/application.html.erb +10 -9
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/rails +3 -3
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +18 -14
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/config/application.rb +12 -22
- data/spec/dummy/config/boot.rb +3 -3
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +4 -18
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +49 -14
- data/spec/dummy/config/environments/production.rb +63 -22
- data/spec/dummy/config/environments/test.rb +29 -12
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +4 -3
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
- data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
- data/spec/dummy/config/locales/en.yml +11 -1
- data/spec/dummy/config/puma.rb +43 -0
- data/spec/dummy/config/routes.rb +1 -54
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/migrate/20161113032308_create_purchases.rb +1 -1
- data/spec/dummy/db/schema.rb +14 -15
- data/spec/dummy/public/404.html +6 -6
- data/spec/dummy/public/422.html +6 -6
- data/spec/dummy/public/500.html +6 -6
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/spec/factories/purchases.rb +6 -22
- data/spec/dummy/spec/lib/active_record_extension_spec.rb +34 -32
- metadata +97 -36
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/secrets.yml +0 -22
data/README.md
CHANGED
@@ -1,23 +1,32 @@
|
|
1
|
-
# Human Attributes
|
1
|
+
# Human Attributes
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/human_attributes.svg)](https://badge.fury.io/rb/human_attributes)
|
3
|
+
[![CircleCI](https://circleci.com/gh/platanus/human_attributes.svg?style=shield)](https://app.circleci.com/pipelines/github/platanus/human_attributes)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/platanus/human_attributes/badge.svg)](https://coveralls.io/github/platanus/human_attributes)
|
2
5
|
|
3
6
|
It's a Gem to convert ActiveRecord models' attributes and methods to human readable representations of these.
|
4
7
|
|
5
|
-
- [
|
6
|
-
- [
|
7
|
-
- [
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
- [
|
15
|
-
|
16
|
-
|
17
|
-
- [
|
18
|
-
- [
|
19
|
-
- [
|
20
|
-
- [
|
8
|
+
- [Human Attributes](#human-attributes)
|
9
|
+
- [Installation](#installation)
|
10
|
+
- [Usage](#usage)
|
11
|
+
- [Formatters](#formatters)
|
12
|
+
- [Numeric](#numeric)
|
13
|
+
- [Date](#date)
|
14
|
+
- [DateTime](#datetime)
|
15
|
+
- [Boolean](#boolean)
|
16
|
+
- [Enumerize](#enumerize)
|
17
|
+
- [Custom Formatter](#custom-formatter)
|
18
|
+
- [Common Options](#common-options)
|
19
|
+
- [Default](#default)
|
20
|
+
- [Suffix](#suffix)
|
21
|
+
- [Multiple Formatters](#multiple-formatters)
|
22
|
+
- [Humanize Active Record Attributes](#humanize-active-record-attributes)
|
23
|
+
- [Integration with Draper Gem](#integration-with-draper-gem)
|
24
|
+
- [Rake Task](#rake-task)
|
25
|
+
- [Testing](#testing)
|
26
|
+
- [Publishing](#publishing)
|
27
|
+
- [Contributing](#contributing)
|
28
|
+
- [Credits](#credits)
|
29
|
+
- [License](#license)
|
21
30
|
|
22
31
|
## Installation
|
23
32
|
|
@@ -501,6 +510,17 @@ bundle exec guard
|
|
501
510
|
|
502
511
|
You need to put **all your tests** in the `/human_attributes/spec/dummy/spec/` directory.
|
503
512
|
|
513
|
+
## Publishing
|
514
|
+
|
515
|
+
On master/main branch...
|
516
|
+
|
517
|
+
1. Change `VERSION` in `lib/gemaker/version.rb`.
|
518
|
+
2. Change `Unreleased` title to current version in `CHANGELOG.md`.
|
519
|
+
3. Run `bundle install`.
|
520
|
+
4. Commit new release. For example: `Releasing v0.1.0`.
|
521
|
+
5. Create tag. For example: `git tag v0.1.0`.
|
522
|
+
6. Push tag. For example: `git push origin v0.1.0`.
|
523
|
+
|
504
524
|
## Contributing
|
505
525
|
|
506
526
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ rescue LoadError
|
|
4
4
|
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
5
|
end
|
6
6
|
|
7
|
-
APP_RAKEFILE = File.expand_path("
|
7
|
+
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
8
8
|
load "rails/tasks/engine.rake"
|
9
9
|
load "rails/tasks/statistics.rake"
|
10
10
|
Bundler::GemHelper.install_tasks
|
data/human_attributes.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$:.push File.expand_path("
|
1
|
+
$:.push File.expand_path("lib", __dir__)
|
2
2
|
|
3
3
|
# Maintain your gem"s version:
|
4
4
|
require "human_attributes/version"
|
@@ -19,14 +19,18 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
s.test_files = Dir["spec/**/*"]
|
21
21
|
|
22
|
-
s.add_dependency "rails", ">= 4.2.0"
|
23
22
|
s.add_dependency "factory_bot"
|
24
|
-
s.
|
25
|
-
|
23
|
+
s.add_dependency "rails", ">= 4.2.0"
|
24
|
+
|
25
|
+
s.add_development_dependency "coveralls"
|
26
|
+
s.add_development_dependency "draper"
|
27
|
+
s.add_development_dependency "enumerize", "~> 2.1"
|
28
|
+
s.add_development_dependency "guard-rspec", "~> 4.7"
|
26
29
|
s.add_development_dependency "pry"
|
27
30
|
s.add_development_dependency "pry-rails"
|
31
|
+
s.add_development_dependency "rspec_junit_formatter"
|
32
|
+
s.add_development_dependency "rspec-rails"
|
33
|
+
s.add_development_dependency "rubocop", "~> 1.9"
|
34
|
+
s.add_development_dependency "rubocop-rails"
|
28
35
|
s.add_development_dependency "sqlite3"
|
29
|
-
s.add_development_dependency "rspec-rails", "~> 3.4"
|
30
|
-
s.add_development_dependency "guard-rspec", "~> 4.7"
|
31
|
-
s.add_development_dependency "coveralls"
|
32
36
|
end
|
@@ -17,14 +17,16 @@ module HumanAttributes
|
|
17
17
|
next if col.name.ends_with?("_id")
|
18
18
|
next if included_attrs && !included_attrs.include?(col.name.to_sym)
|
19
19
|
next if excluded_attrs && excluded_attrs.include?(col.name.to_sym)
|
20
|
+
|
20
21
|
humanize_from_type(col)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def humanizers
|
25
26
|
return [] unless @humanizers
|
27
|
+
|
26
28
|
@humanizers.uniq!
|
27
|
-
@humanizers.
|
29
|
+
@humanizers.select! { |method| method_defined?(method) }
|
28
30
|
@humanizers
|
29
31
|
end
|
30
32
|
|
@@ -60,10 +62,10 @@ module HumanAttributes
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
|
-
ActiveRecord::Base.
|
65
|
+
ActiveRecord::Base.include(HumanAttributes::Extension)
|
64
66
|
|
65
67
|
begin
|
66
|
-
Draper::Decorator.
|
68
|
+
Draper::Decorator.include(HumanAttributes::Extension)
|
67
69
|
rescue NameError
|
68
70
|
nil
|
69
71
|
end
|
data/spec/dummy/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
2
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
3
|
|
4
|
-
|
4
|
+
require_relative "config/application"
|
5
5
|
|
6
6
|
Rails.application.load_tasks
|
@@ -6,9 +6,9 @@
|
|
6
6
|
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
7
|
*
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any
|
10
|
-
*
|
11
|
-
* file per style scope.
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
12
|
*
|
13
13
|
*= require_tree .
|
14
14
|
*= require_self
|
@@ -5,9 +5,11 @@
|
|
5
5
|
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
6
|
//
|
7
7
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
9
|
//
|
10
10
|
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
11
|
// about supported directives.
|
12
12
|
//
|
13
|
+
//= require rails-ujs
|
14
|
+
//= require activestorage
|
13
15
|
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
7
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</head>
|
9
|
-
<body>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
<%= csp_meta_tag %>
|
10
8
|
|
11
|
-
<%=
|
9
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
10
|
+
</head>
|
12
11
|
|
13
|
-
|
12
|
+
<body>
|
13
|
+
<%= yield %>
|
14
|
+
</body>
|
14
15
|
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
data/spec/dummy/bin/rails
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
APP_PATH = File.expand_path('
|
3
|
-
require_relative
|
4
|
-
require
|
2
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
3
|
+
require_relative "../config/boot"
|
4
|
+
require "rails/commands"
|
data/spec/dummy/bin/rake
CHANGED
data/spec/dummy/bin/setup
CHANGED
@@ -1,29 +1,33 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require
|
2
|
+
require "fileutils"
|
3
3
|
|
4
4
|
# path to your application root.
|
5
|
-
APP_ROOT =
|
5
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def system!(*args)
|
8
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
9
|
+
end
|
10
|
+
|
11
|
+
FileUtils.chdir APP_ROOT do
|
12
|
+
# This script is a way to set up or update your development environment automatically.
|
13
|
+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
|
14
|
+
# Add necessary setup steps to this file.
|
10
15
|
|
11
|
-
puts
|
12
|
-
system
|
13
|
-
system
|
16
|
+
puts '== Installing dependencies =='
|
17
|
+
system! 'gem install bundler --conservative'
|
18
|
+
system('bundle check') || system!('bundle install')
|
14
19
|
|
15
20
|
# puts "\n== Copying sample files =="
|
16
|
-
# unless File.exist?(
|
17
|
-
#
|
21
|
+
# unless File.exist?('config/database.yml')
|
22
|
+
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
|
18
23
|
# end
|
19
24
|
|
20
25
|
puts "\n== Preparing database =="
|
21
|
-
system
|
26
|
+
system! 'bin/rails db:prepare'
|
22
27
|
|
23
28
|
puts "\n== Removing old logs and tempfiles =="
|
24
|
-
system
|
25
|
-
system "rm -rf tmp/cache"
|
29
|
+
system! 'bin/rails log:clear tmp:clear'
|
26
30
|
|
27
31
|
puts "\n== Restarting application server =="
|
28
|
-
system
|
32
|
+
system! 'bin/rails restart'
|
29
33
|
end
|
data/spec/dummy/config.ru
CHANGED
@@ -1,32 +1,22 @@
|
|
1
|
-
|
1
|
+
require_relative "boot"
|
2
2
|
|
3
|
-
|
4
|
-
require "active_record/railtie"
|
5
|
-
require "action_controller/railtie"
|
6
|
-
require "action_mailer/railtie"
|
7
|
-
require "action_view/railtie"
|
8
|
-
require "sprockets/railtie"
|
9
|
-
# require "rails/test_unit/railtie"
|
3
|
+
require "rails/all"
|
10
4
|
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
11
7
|
Bundler.require(*Rails.groups)
|
12
8
|
require "human_attributes"
|
13
9
|
|
14
10
|
module Dummy
|
15
11
|
class Application < Rails::Application
|
16
|
-
|
17
|
-
# Application configuration should go into files in config/initializers
|
18
|
-
# -- all .rb files in that directory are automatically loaded.
|
12
|
+
config.load_defaults Rails::VERSION::STRING.to_f
|
19
13
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
|
24
|
-
#
|
25
|
-
# config.
|
26
|
-
# config.
|
27
|
-
|
28
|
-
# Do not swallow errors in after_commit/after_rollback callbacks.
|
29
|
-
config.active_record.raise_in_transactional_callbacks = true
|
14
|
+
# Configuration for the application, engines, and railties goes here.
|
15
|
+
#
|
16
|
+
# These settings can be overridden in specific environments using the files
|
17
|
+
# in config/environments, which are processed later.
|
18
|
+
#
|
19
|
+
# config.time_zone = "Central Time (US & Canada)"
|
20
|
+
# config.eager_load_paths << Rails.root.join("extras")
|
30
21
|
end
|
31
22
|
end
|
32
|
-
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Set up gems listed in the Gemfile.
|
2
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
|
3
3
|
|
4
|
-
require
|
5
|
-
$LOAD_PATH.unshift File.expand_path('
|
4
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
5
|
+
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|