diff --git a/Gemfile b/Gemfile index 21bb4f6..ce06b9a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,6 @@ -source 'https://rubygems.org' +# frozen_string_literal: true + +source "https://rubygems.org" # Declare your gem's dependencies in options_model.gemspec. # Bundler will treat runtime dependencies like base dependencies, and diff --git a/Rakefile b/Rakefile index dfe9f11..de59ed3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,33 +1,29 @@ +# frozen_string_literal: true + begin - require 'bundler/setup' + require "bundler/setup" rescue LoadError - puts 'You must `gem install bundler` and `bundle install` to run rake tasks' + puts "You must `gem install bundler` and `bundle install` to run rake tasks" end -require 'rdoc/task' +require "rdoc/task" RDoc::Task.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'OptionsModel' - rdoc.options << '--line-numbers' - rdoc.rdoc_files.include('README.md') - rdoc.rdoc_files.include('lib/**/*.rb') + rdoc.rdoc_dir = "rdoc" + rdoc.title = "OptionsModel" + rdoc.options << "--line-numbers" + rdoc.rdoc_files.include("README.md") + rdoc.rdoc_files.include("lib/**/*.rb") end +require "bundler/gem_tasks" - - - - -require 'bundler/gem_tasks' - -require 'rake/testtask' +require "rake/testtask" Rake::TestTask.new(:test) do |t| - t.libs << 'test' - t.pattern = 'test/**/*_test.rb' + t.libs << "test" + t.pattern = "test/**/*_test.rb" t.verbose = false end - task default: :test diff --git a/bin/test b/bin/test index 2f98ca3..267eeaa 100755 --- a/bin/test +++ b/bin/test @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + $: << File.expand_path(File.expand_path("../../test", __FILE__)) require "bundler/setup" diff --git a/lib/options_model.rb b/lib/options_model.rb index a9d5145..c5dfa2c 100644 --- a/lib/options_model.rb +++ b/lib/options_model.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_model" require "active_model/type" @@ -9,5 +11,4 @@ require "options_model/base" module OptionsModel - end diff --git a/lib/options_model/base.rb b/lib/options_model/base.rb index 5b9fa44..db3e2ce 100644 --- a/lib/options_model/base.rb +++ b/lib/options_model/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OptionsModel class Base include ActiveModel::Model diff --git a/lib/options_model/concerns/attribute_assignment.rb b/lib/options_model/concerns/attribute_assignment.rb index 404669d..df5a0ed 100644 --- a/lib/options_model/concerns/attribute_assignment.rb +++ b/lib/options_model/concerns/attribute_assignment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OptionsModel module Concerns module AttributeAssignment diff --git a/lib/options_model/concerns/attributes.rb b/lib/options_model/concerns/attributes.rb index 6eb610e..09f00ce 100644 --- a/lib/options_model/concerns/attributes.rb +++ b/lib/options_model/concerns/attributes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OptionsModel module Concerns module Attributes diff --git a/lib/options_model/concerns/name_hacking.rb b/lib/options_model/concerns/name_hacking.rb index 407804c..901e2dc 100644 --- a/lib/options_model/concerns/name_hacking.rb +++ b/lib/options_model/concerns/name_hacking.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OptionsModel module Concerns module NameHacking diff --git a/lib/options_model/concerns/serialization.rb b/lib/options_model/concerns/serialization.rb index 92a765d..781397a 100644 --- a/lib/options_model/concerns/serialization.rb +++ b/lib/options_model/concerns/serialization.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OptionsModel module Concerns module Serialization @@ -8,9 +10,11 @@ def to_h hash.merge! unused_attributes if self.class.with_unused_attributes? self.class.attribute_names_for_inlining.each do |name| - hash[name] = send(:"#{name}") + hash[name] = send(name) + end + self.class.attribute_names_for_nesting.each do |name| + hash[name] = send(name).to_h end - hash.merge! nested_attributes.reduce({}) { |h, (k, v)| h[k] = v.to_h; h } hash end diff --git a/lib/options_model/version.rb b/lib/options_model/version.rb index 7a00f43..26622f7 100644 --- a/lib/options_model/version.rb +++ b/lib/options_model/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OptionsModel VERSION = "0.0.5".freeze end diff --git a/lib/tasks/options_model_tasks.rake b/lib/tasks/options_model_tasks.rake index 1ab3133..f1e9920 100644 --- a/lib/tasks/options_model_tasks.rake +++ b/lib/tasks/options_model_tasks.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true # desc "Explaining what the task does" # task :options_model do # # Task goes here diff --git a/options_model.gemspec b/options_model.gemspec index 7fafc1b..55a223e 100644 --- a/options_model.gemspec +++ b/options_model.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile index e85f913..d2a78aa 100644 --- a/test/dummy/Rakefile +++ b/test/dummy/Rakefile @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative 'config/application' +require_relative "config/application" Rails.application.load_tasks diff --git a/test/dummy/app/channels/application_cable/channel.rb b/test/dummy/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/test/dummy/app/channels/application_cable/channel.rb +++ b/test/dummy/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/test/dummy/app/channels/application_cable/connection.rb b/test/dummy/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/test/dummy/app/channels/application_cable/connection.rb +++ b/test/dummy/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb index 1c07694..280cc28 100644 --- a/test/dummy/app/controllers/application_controller.rb +++ b/test/dummy/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base protect_from_forgery with: :exception end diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/test/dummy/app/helpers/application_helper.rb +++ b/test/dummy/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/test/dummy/app/jobs/application_job.rb b/test/dummy/app/jobs/application_job.rb index a009ace..d92ffdd 100644 --- a/test/dummy/app/jobs/application_job.rb +++ b/test/dummy/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/test/dummy/bin/bundle b/test/dummy/bin/bundle index 66e9889..277e128 100755 --- a/test/dummy/bin/bundle +++ b/test/dummy/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') +# frozen_string_literal: true + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__) +load Gem.bin_path("bundler", "bundle") diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails index 0739660..22f2d8d 100755 --- a/test/dummy/bin/rails +++ b/test/dummy/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +# frozen_string_literal: true + +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake index 1724048..e436ea5 100755 --- a/test/dummy/bin/rake +++ b/test/dummy/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby -require_relative '../config/boot' -require 'rake' +# frozen_string_literal: true + +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/test/dummy/bin/setup b/test/dummy/bin/setup index 93a2160..9b229da 100755 --- a/test/dummy/bin/setup +++ b/test/dummy/bin/setup @@ -1,10 +1,12 @@ #!/usr/bin/env ruby -require 'pathname' -require 'fileutils' +# frozen_string_literal: true + +require "pathname" +require "fileutils" include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path("../../", __FILE__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -14,17 +16,16 @@ chdir APP_ROOT do # This script is a starting point to setup your application. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # Install JavaScript dependencies if using Yarn # system('bin/yarn') - puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/test/dummy/bin/update b/test/dummy/bin/update index dc15867..d42bc68 100755 --- a/test/dummy/bin/update +++ b/test/dummy/bin/update @@ -1,10 +1,12 @@ #!/usr/bin/env ruby -require 'pathname' -require 'fileutils' +# frozen_string_literal: true + +require "pathname" +require "fileutils" include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path("../../", __FILE__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -14,13 +16,13 @@ chdir APP_ROOT do # This script is a way to update your development environment automatically. # Add necessary update steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/test/dummy/bin/yarn b/test/dummy/bin/yarn index c2bacef..c9b7498 100755 --- a/test/dummy/bin/yarn +++ b/test/dummy/bin/yarn @@ -1,5 +1,7 @@ #!/usr/bin/env ruby -VENDOR_PATH = File.expand_path('..', __dir__) +# frozen_string_literal: true + +VENDOR_PATH = File.expand_path("..", __dir__) Dir.chdir(VENDOR_PATH) do begin exec "yarnpkg #{ARGV.join(" ")}" diff --git a/test/dummy/config.ru b/test/dummy/config.ru index f7ba0b5..bff88d6 100644 --- a/test/dummy/config.ru +++ b/test/dummy/config.ru @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. -require_relative 'config/environment' +require_relative "config/environment" run Rails.application diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 0a1c107..970e8ad 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -1,4 +1,6 @@ -require_relative 'boot' +# frozen_string_literal: true + +require_relative "boot" # Pick the frameworks you want: # require "active_record/railtie" @@ -23,4 +25,3 @@ class Application < Rails::Application # -- all .rb files in that directory are automatically loaded. end end - diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index c9aef85..59459d4 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) -$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__) +require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) +$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__) diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb index 426333b..7df99e8 100644 --- a/test/dummy/config/environment.rb +++ b/test/dummy/config/environment.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Load the Rails application. -require_relative 'application' +require_relative "application" # Initialize the Rails application. Rails.application.initialize! diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 97e9b96..e7d056d 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -13,12 +15,12 @@ config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. - if Rails.root.join('tmp/caching-dev.txt').exist? + if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" + "Cache-Control" => "public, max-age=#{2.days.seconds.to_i}" } else config.action_controller.perform_caching = false @@ -29,7 +31,6 @@ # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raises error for missing translations # config.action_view.raise_on_missing_translations = true diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index 5dcdad9..78d2f09 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -21,8 +23,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? - + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 6fd7f98..454733e 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -15,7 +17,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.seconds.to_i}" } # Show full error reports and disable caching. diff --git a/test/dummy/config/initializers/application_controller_renderer.rb b/test/dummy/config/initializers/application_controller_renderer.rb index 51639b6..315ac48 100644 --- a/test/dummy/config/initializers/application_controller_renderer.rb +++ b/test/dummy/config/initializers/application_controller_renderer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ApplicationController.renderer.defaults.merge!( diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb index 59385cd..d0f0d3b 100644 --- a/test/dummy/config/initializers/backtrace_silencers.rb +++ b/test/dummy/config/initializers/backtrace_silencers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/test/dummy/config/initializers/cookies_serializer.rb b/test/dummy/config/initializers/cookies_serializer.rb index 5a6a32d..ee8dff9 100644 --- a/test/dummy/config/initializers/cookies_serializer.rb +++ b/test/dummy/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb index 4a994e1..7a4f47b 100644 --- a/test/dummy/config/initializers/filter_parameter_logging.rb +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb index ac033bf..aa7435f 100644 --- a/test/dummy/config/initializers/inflections.rb +++ b/test/dummy/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb index dc18996..6e1d16f 100644 --- a/test/dummy/config/initializers/mime_types.rb +++ b/test/dummy/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/test/dummy/config/initializers/wrap_parameters.rb index 633c1c8..e7148a3 100644 --- a/test/dummy/config/initializers/wrap_parameters.rb +++ b/test/dummy/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/test/dummy/config/puma.rb b/test/dummy/config/puma.rb index 1e19380..55bd3da 100644 --- a/test/dummy/config/puma.rb +++ b/test/dummy/config/puma.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 787824f..47cc16e 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/test/dummy/config/spring.rb b/test/dummy/config/spring.rb index c9119b4..ff5ba06 100644 --- a/test/dummy/config/spring.rb +++ b/test/dummy/config/spring.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + %w( .ruby-version .rbenv-vars diff --git a/test/options_model_test.rb b/test/options_model_test.rb index 70ff2fd..2e32c1e 100644 --- a/test/options_model_test.rb +++ b/test/options_model_test.rb @@ -1,4 +1,6 @@ -require 'test_helper' +# frozen_string_literal: true + +require "test_helper" class OptionsModel::Test < ActiveSupport::TestCase test "truth" do diff --git a/test/test_helper.rb b/test/test_helper.rb index 36d839d..078c5a9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) require "rails/test_help" @@ -5,7 +7,7 @@ # to be shown. Minitest.backtrace_filter = Minitest::BacktraceFilter.new -Rails::TestUnitReporter.executable = 'bin/test' +Rails::TestUnitReporter.executable = "bin/test" # Load fixtures from the engine if ActiveSupport::TestCase.respond_to?(:fixture_path=)