human_attributes 0.6.0 → 0.7.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +104 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.rubocop.yml +65 -594
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +6 -0
  7. data/Gemfile.lock +216 -144
  8. data/Guardfile +4 -4
  9. data/README.md +37 -17
  10. data/Rakefile +1 -1
  11. data/human_attributes.gemspec +11 -7
  12. data/lib/human_attributes/extension.rb +5 -3
  13. data/lib/human_attributes/formatters/base.rb +1 -0
  14. data/lib/human_attributes/formatters/enumerize.rb +1 -0
  15. data/lib/human_attributes/formatters_builder.rb +1 -0
  16. data/lib/human_attributes/version.rb +1 -1
  17. data/spec/dummy/Rakefile +1 -1
  18. data/spec/dummy/app/assets/config/manifest.js +3 -0
  19. data/spec/dummy/app/assets/stylesheets/application.css +3 -3
  20. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  21. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  22. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  23. data/spec/dummy/app/{assets/javascripts → javascript/packs}/application.js +3 -1
  24. data/spec/dummy/app/jobs/application_job.rb +7 -0
  25. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  26. data/spec/dummy/app/models/application_record.rb +3 -0
  27. data/spec/dummy/app/models/purchase.rb +1 -1
  28. data/spec/dummy/app/views/layouts/application.html.erb +10 -9
  29. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  30. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  31. data/spec/dummy/bin/rails +3 -3
  32. data/spec/dummy/bin/rake +2 -2
  33. data/spec/dummy/bin/setup +18 -14
  34. data/spec/dummy/config.ru +3 -1
  35. data/spec/dummy/config/application.rb +12 -22
  36. data/spec/dummy/config/boot.rb +3 -3
  37. data/spec/dummy/config/cable.yml +10 -0
  38. data/spec/dummy/config/database.yml +4 -18
  39. data/spec/dummy/config/environment.rb +1 -1
  40. data/spec/dummy/config/environments/development.rb +49 -14
  41. data/spec/dummy/config/environments/production.rb +63 -22
  42. data/spec/dummy/config/environments/test.rb +29 -12
  43. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  44. data/spec/dummy/config/initializers/assets.rb +4 -3
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
  46. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  47. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  48. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
  49. data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
  50. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  51. data/spec/dummy/config/locales/en.yml +11 -1
  52. data/spec/dummy/config/puma.rb +43 -0
  53. data/spec/dummy/config/routes.rb +1 -54
  54. data/spec/dummy/config/storage.yml +34 -0
  55. data/spec/dummy/db/migrate/20161113032308_create_purchases.rb +1 -1
  56. data/spec/dummy/db/schema.rb +14 -15
  57. data/spec/dummy/public/404.html +6 -6
  58. data/spec/dummy/public/422.html +6 -6
  59. data/spec/dummy/public/500.html +6 -6
  60. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  61. data/spec/dummy/public/apple-touch-icon.png +0 -0
  62. data/spec/dummy/spec/factories/purchases.rb +6 -22
  63. data/spec/dummy/spec/lib/active_record_extension_spec.rb +34 -32
  64. metadata +97 -36
  65. data/spec/dummy/README.rdoc +0 -28
  66. data/spec/dummy/bin/bundle +0 -3
  67. data/spec/dummy/config/initializers/session_store.rb +0 -3
  68. data/spec/dummy/config/secrets.yml +0 -22
data/README.md CHANGED
@@ -1,23 +1,32 @@
1
- # Human Attributes [![Gem Version](https://badge.fury.io/rb/human_attributes.svg)](https://badge.fury.io/rb/human_attributes) [![Build Status](https://travis-ci.org/platanus/human_attributes.svg?branch=master)](https://travis-ci.org/platanus/human_attributes) [![Coverage Status](https://coveralls.io/repos/github/platanus/human_attributes/badge.svg)](https://coveralls.io/github/platanus/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
- - [Installation](#installation)
6
- - [Usage](#usage)
7
- - [Formatters](#formatters)
8
- - [Numeric](#numeric)
9
- - [Date](#date)
10
- - [DateTime](#datetime)
11
- - [Boolean](#boolean)
12
- - [Enumerize](#enumerize)
13
- - [Custom Formatter](#custom-formatter)
14
- - [Common Options](#common-options)
15
- - [Default](#default)
16
- - [Suffix](#suffix)
17
- - [Multiple Formatters](#multiple-formatters)
18
- - [Humanize Active Record Attributes](#humanize-active-record-attributes)
19
- - [Integration with Draper Gem](#integration-with-draper-gem)
20
- - [Rake Task](#rake-task)
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("../spec/dummy/Rakefile", __FILE__)
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
@@ -1,4 +1,4 @@
1
- $:.push File.expand_path("../lib", __FILE__)
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.add_development_dependency "enumerize", "~> 1", ">= 1.1.1"
25
- s.add_development_dependency "draper", "~> 2.1.0"
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.reject! { |method| !method_defined?(method) }
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.send(:include, HumanAttributes::Extension)
65
+ ActiveRecord::Base.include(HumanAttributes::Extension)
64
66
 
65
67
  begin
66
- Draper::Decorator.send(:include, HumanAttributes::Extension)
68
+ Draper::Decorator.include(HumanAttributes::Extension)
67
69
  rescue NameError
68
70
  nil
69
71
  end
@@ -16,6 +16,7 @@ module HumanAttributes
16
16
  def method_name
17
17
  return "human_#{attribute}" if suffix.blank?
18
18
  return "#{attribute}_#{suffix_by_type(type)}" if suffix == true
19
+
19
20
  "#{attribute}_#{suffix}"
20
21
  end
21
22
 
@@ -3,6 +3,7 @@ module HumanAttributes
3
3
  class Enumerize < Base
4
4
  def apply(_instance, value)
5
5
  return unless value
6
+
6
7
  raise_error('NotEnumerizeAttribute') unless value.class.to_s == "Enumerize::Value"
7
8
  value.text
8
9
  end
@@ -37,6 +37,7 @@ module HumanAttributes
37
37
 
38
38
  def get_options(options)
39
39
  return {} if options == true
40
+
40
41
  raise_error('InvalidAttributeOptions') unless options.is_a?(Hash)
41
42
  options
42
43
  end
@@ -1,3 +1,3 @@
1
1
  module HumanAttributes
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  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
- require File.expand_path('../config/application', __FILE__)
4
+ require_relative "config/application"
5
5
 
6
6
  Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
3
+ //= link human_attributes_manifest.js
@@ -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 styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
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
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -1,5 +1,2 @@
1
1
  class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
5
2
  end
@@ -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
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -16,7 +16,7 @@
16
16
 
17
17
  require "enumerize"
18
18
 
19
- class Purchase < ActiveRecord::Base
19
+ class Purchase < ApplicationRecord
20
20
  extend Enumerize
21
21
 
22
22
  STATES = %i{pending canceled finished}
@@ -1,14 +1,15 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
- <%= csrf_meta_tags %>
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
- <%= yield %>
9
+ <%= stylesheet_link_tag 'application', media: 'all' %>
10
+ </head>
12
11
 
13
- </body>
12
+ <body>
13
+ <%= yield %>
14
+ </body>
14
15
  </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </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('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative "../config/boot"
4
+ require "rails/commands"
data/spec/dummy/bin/rake CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require_relative '../config/boot'
3
- require 'rake'
2
+ require_relative "../config/boot"
3
+ require "rake"
4
4
  Rake.application.run
data/spec/dummy/bin/setup CHANGED
@@ -1,29 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
- require 'pathname'
2
+ require "fileutils"
3
3
 
4
4
  # path to your application root.
5
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
5
+ APP_ROOT = File.expand_path('..', __dir__)
6
6
 
7
- Dir.chdir APP_ROOT do
8
- # This script is a starting point to setup your application.
9
- # Add necessary setup steps to this file:
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 "== Installing dependencies =="
12
- system "gem install bundler --conservative"
13
- system "bundle check || bundle install"
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?("config/database.yml")
17
- # system "cp config/database.yml.sample config/database.yml"
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 "bin/rake db:setup"
26
+ system! 'bin/rails db:prepare'
22
27
 
23
28
  puts "\n== Removing old logs and tempfiles =="
24
- system "rm -f log/*"
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 "touch tmp/restart.txt"
32
+ system! 'bin/rails restart'
29
33
  end
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,6 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require_relative "config/environment"
4
+
4
5
  run Rails.application
6
+ Rails.application.load_server
@@ -1,32 +1,22 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require_relative "boot"
2
2
 
3
- # Pick the frameworks you want:
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
- # Settings in config/environments/* take precedence over those specified here.
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
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
- # config.time_zone = 'Central Time (US & Canada)'
23
-
24
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
- # config.i18n.default_locale = :de
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
-
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
3
 
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
4
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: test
6
+
7
+ production:
8
+ adapter: redis
9
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10
+ channel_prefix: dummy_production