From 051251ea4e08aa05856e1e35be98d616c4ab5ee0 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Thu, 5 Jan 2023 21:46:21 +0530 Subject: [PATCH 01/23] first commit --- .circleci/config.yml | 89 ------------------- Gemfile | 2 + README.md | 4 - bin/test | 5 -- blueprinter.gemspec | 27 +++--- lib/blueprinter.rb | 2 + lib/blueprinter/base.rb | 2 + lib/blueprinter/blueprinter_error.rb | 2 + lib/blueprinter/configuration.rb | 2 + lib/blueprinter/deprecation.rb | 4 +- lib/blueprinter/empty_types.rb | 8 +- lib/blueprinter/extractor.rb | 2 + .../extractors/association_extractor.rb | 2 + lib/blueprinter/extractors/auto_extractor.rb | 2 + lib/blueprinter/extractors/block_extractor.rb | 2 + lib/blueprinter/extractors/hash_extractor.rb | 2 + .../extractors/public_send_extractor.rb | 2 + lib/blueprinter/field.rb | 2 + .../formatters/date_time_formatter.rb | 2 + lib/blueprinter/helpers/base_helpers.rb | 2 + lib/blueprinter/helpers/type_helpers.rb | 2 + lib/blueprinter/transformer.rb | 2 + lib/blueprinter/version.rb | 4 +- lib/blueprinter/view.rb | 2 + lib/blueprinter/view_collection.rb | 2 + .../blueprinter/blueprint_generator.rb | 2 + .../blueprinter/templates/blueprint.rb | 2 + lib/tasks/blueprinter_tasks.rake | 4 - spec/activerecord_helper.rb | 2 + spec/benchmark_helper.rb | 2 + spec/benchmarks/active_record_big_o_test.rb | 2 + spec/benchmarks/active_record_ips_test.rb | 2 + spec/benchmarks/big_o_test.rb | 2 + spec/benchmarks/ips_test.rb | 2 + spec/factories/model_factories.rb | 2 + spec/generator_helper.rb | 2 + spec/generators/blueprint_generator_spec.rb | 2 + spec/generators/shared.rb | 3 +- spec/integrations/base_spec.rb | 2 + .../shared/base_render_examples.rb | 2 + spec/spec_helper.rb | 2 + spec/units/configuration_spec.rb | 2 + spec/units/date_time_formatter_spec.rb | 2 + spec/units/deprecation_spec.rb | 2 + spec/units/view_spec.rb | 2 + 45 files changed, 98 insertions(+), 122 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100755 bin/test delete mode 100644 lib/tasks/blueprinter_tasks.rake diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 9534cbe7..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,89 +0,0 @@ -version: 2.1 - -steps: &steps_spec - - checkout - - run: - name: Installing ruby dependencies - command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle - - run: - command: bundle exec rake - - when: - condition: << parameters.benchmark >> - steps: - - run: - command: bundle exec rake benchmarks - -jobs: - ruby-2_2: - parameters: - benchmark: - type: boolean - default: false - steps: *steps_spec - docker: - - image: ruby:2.2 - ruby-2_3: - parameters: - benchmark: - type: boolean - default: true - steps: *steps_spec - docker: - - image: ruby:2.3 - ruby-2_4: - parameters: - benchmark: - type: boolean - default: true - steps: *steps_spec - docker: - - image: ruby:2.4 - ruby-2_5: - parameters: - benchmark: - type: boolean - default: true - steps: *steps_spec - docker: - - image: ruby:2.5 - release-gem: - steps: - - checkout - - run: - name: Installing ruby dependencies - command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle - - run: - name: Sign in to Github as CircleCI Bot - command: | - git config --global user.email "$CIRCLECI_GIT_BOT_GIT_EMAIL" - git config --global user.name "$CIRCLECI_GIT_BOT_NAME" - - run: - name: Auth RubyGems - command: | - mkdir ~/.gem - install -m 0600 /dev/null ~/.gem/credentials - echo -e "---\n:rubygems_api_key: $RUBY_GEMS_API_KEY" > ~/.gem/credentials - - deploy: - name: Release New Gem Version - command: | - GEM_VERSION=$(ruby -r "./lib/blueprinter/version.rb" -e "puts Blueprinter::VERSION") - echo "Attempting to release version '$GEM_VERSION' of Blueprinter..." - bundle exec rake release || true # Don't fail when deploy does not take place - docker: - - image: ruby:2.5 - -workflows: - version: 2 - test: - jobs: - - ruby-2_2 - - ruby-2_3 - - ruby-2_4 - - ruby-2_5 - release: - jobs: - - release-gem: - filters: - branches: - only: - - master diff --git a/Gemfile b/Gemfile index e94d938f..fd0b6ce2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Declare your gem's dependencies in blueprinter.gemspec. diff --git a/README.md b/README.md index e0e07c77..8b06f7af 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ -[![CircleCI](https://circleci.com/gh/procore/blueprinter.svg?style=svg)](https://circleci.com/gh/procore/blueprinter) -[![Gem Version](https://badge.fury.io/rb/blueprinter.svg)](https://badge.fury.io/rb/blueprinter) -[![Gitter chat](https://badges.gitter.im/procore/blueprinter.svg)](https://gitter.im/blueprinter-gem/community) - # Blueprinter diff --git a/bin/test b/bin/test deleted file mode 100755 index 2f98ca32..00000000 --- a/bin/test +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env ruby -$: << File.expand_path(File.expand_path("../../test", __FILE__)) - -require "bundler/setup" -require "rails/plugin/test" diff --git a/blueprinter.gemspec b/blueprinter.gemspec index 8cb9b026..b2361946 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: @@ -16,19 +18,16 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "CHANGELOG.md", "MIT-LICENSE", "Rakefile", "README.md"] - s.required_ruby_version = '>= 2.2.2' + s.required_ruby_version = '>= 2.6.9' - s.add_development_dependency "factory_bot" - s.add_development_dependency "nokogiri", ">= 1.8.2" - s.add_development_dependency "oj", "~> 3.0" - s.add_development_dependency "yajl-ruby", "~> 1.4.1" - s.add_development_dependency "pry" - s.add_development_dependency "rake" - s.add_development_dependency "activerecord", "~> 5.1.2" - s.add_development_dependency "rspec", "~> 3.7" - # rspec-rails >= 4.0.0 does not support ruby 2.2 - s.add_development_dependency 'rspec-rails', '< 4.0.0' - s.add_development_dependency "sqlite3", '~> 1.3.6' - s.add_development_dependency "yard", "~> 0.9.11" - s.add_development_dependency "ammeter", "~> 1.1.4" + s.add_development_dependency "factory_bot", "~> 6.2" + s.add_development_dependency "oj", "~> 3.13" + s.add_development_dependency "yajl-ruby", "~> 1.4" + s.add_development_dependency "pry", "~> 0.14" + s.add_development_dependency "activerecord", "~> 7.0" + s.add_development_dependency "rspec", "~> 3.12" + s.add_development_dependency "rspec-rails", "~> 6.0" + s.add_development_dependency "sqlite3", "~> 1.5" + s.add_development_dependency "yard", "~> 0.9" + s.add_development_dependency "ammeter", "~> 1.1" end diff --git a/lib/blueprinter.rb b/lib/blueprinter.rb index e5ba580a..7c1f1e74 100644 --- a/lib/blueprinter.rb +++ b/lib/blueprinter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'blueprinter/base' module Blueprinter diff --git a/lib/blueprinter/base.rb b/lib/blueprinter/base.rb index 84644e96..3943a06f 100644 --- a/lib/blueprinter/base.rb +++ b/lib/blueprinter/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'blueprinter_error' require_relative 'configuration' require_relative 'deprecation' diff --git a/lib/blueprinter/blueprinter_error.rb b/lib/blueprinter/blueprinter_error.rb index 7c4d281e..2428fea2 100644 --- a/lib/blueprinter/blueprinter_error.rb +++ b/lib/blueprinter/blueprinter_error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter class BlueprinterError < StandardError; end end diff --git a/lib/blueprinter/configuration.rb b/lib/blueprinter/configuration.rb index abab8aff..3ceef245 100644 --- a/lib/blueprinter/configuration.rb +++ b/lib/blueprinter/configuration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter class Configuration attr_accessor :association_default, :datetime_format, :deprecations, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default, :default_transformers diff --git a/lib/blueprinter/deprecation.rb b/lib/blueprinter/deprecation.rb index 0c6cbd2c..85f95331 100644 --- a/lib/blueprinter/deprecation.rb +++ b/lib/blueprinter/deprecation.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # @api private module Blueprinter class Deprecation class << self VALID_BEHAVIORS = %i(silence stderror raise).freeze - MESSAGE_PREFIX = "[DEPRECATION::WARNING] Blueprinter:".freeze + MESSAGE_PREFIX = "[DEPRECATION::WARNING] Blueprinter:" def report(message) full_msg = qualified_message(message) diff --git a/lib/blueprinter/empty_types.rb b/lib/blueprinter/empty_types.rb index 611e3ab7..a3903fde 100644 --- a/lib/blueprinter/empty_types.rb +++ b/lib/blueprinter/empty_types.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require_relative 'helpers/type_helpers' module Blueprinter - EMPTY_COLLECTION = "empty_collection".freeze - EMPTY_HASH = "empty_hash".freeze - EMPTY_STRING = "empty_string".freeze + EMPTY_COLLECTION = "empty_collection" + EMPTY_HASH = "empty_hash" + EMPTY_STRING = "empty_string" module EmptyTypes include TypeHelpers diff --git a/lib/blueprinter/extractor.rb b/lib/blueprinter/extractor.rb index c73cbfa5..9e7009d4 100644 --- a/lib/blueprinter/extractor.rb +++ b/lib/blueprinter/extractor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter class Extractor def extract(_field_name, _object, _local_options, _options={}) diff --git a/lib/blueprinter/extractors/association_extractor.rb b/lib/blueprinter/extractors/association_extractor.rb index d6cd7f6a..0f77331d 100644 --- a/lib/blueprinter/extractors/association_extractor.rb +++ b/lib/blueprinter/extractors/association_extractor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter # @api private class AssociationExtractor < Extractor diff --git a/lib/blueprinter/extractors/auto_extractor.rb b/lib/blueprinter/extractors/auto_extractor.rb index d256e44b..226ba214 100644 --- a/lib/blueprinter/extractors/auto_extractor.rb +++ b/lib/blueprinter/extractors/auto_extractor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter # @api private class AutoExtractor < Extractor diff --git a/lib/blueprinter/extractors/block_extractor.rb b/lib/blueprinter/extractors/block_extractor.rb index 727dc711..043c34b1 100644 --- a/lib/blueprinter/extractors/block_extractor.rb +++ b/lib/blueprinter/extractors/block_extractor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter # @api private class BlockExtractor < Extractor diff --git a/lib/blueprinter/extractors/hash_extractor.rb b/lib/blueprinter/extractors/hash_extractor.rb index f2b28e8b..714739df 100644 --- a/lib/blueprinter/extractors/hash_extractor.rb +++ b/lib/blueprinter/extractors/hash_extractor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter # @api private class HashExtractor < Extractor diff --git a/lib/blueprinter/extractors/public_send_extractor.rb b/lib/blueprinter/extractors/public_send_extractor.rb index 99c205ad..d0401352 100644 --- a/lib/blueprinter/extractors/public_send_extractor.rb +++ b/lib/blueprinter/extractors/public_send_extractor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter # @api private class PublicSendExtractor < Extractor diff --git a/lib/blueprinter/field.rb b/lib/blueprinter/field.rb index 91e0d913..32e3b07a 100644 --- a/lib/blueprinter/field.rb +++ b/lib/blueprinter/field.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @api private class Blueprinter::Field attr_reader :method, :name, :extractor, :options, :blueprint diff --git a/lib/blueprinter/formatters/date_time_formatter.rb b/lib/blueprinter/formatters/date_time_formatter.rb index db358a13..a24c0fc9 100644 --- a/lib/blueprinter/formatters/date_time_formatter.rb +++ b/lib/blueprinter/formatters/date_time_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter class DateTimeFormatter InvalidDateTimeFormatterError = Class.new(BlueprinterError) diff --git a/lib/blueprinter/helpers/base_helpers.rb b/lib/blueprinter/helpers/base_helpers.rb index 99b40845..cb770a9c 100644 --- a/lib/blueprinter/helpers/base_helpers.rb +++ b/lib/blueprinter/helpers/base_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter module BaseHelpers def self.included(base) diff --git a/lib/blueprinter/helpers/type_helpers.rb b/lib/blueprinter/helpers/type_helpers.rb index 3d878d70..dde3d8d6 100644 --- a/lib/blueprinter/helpers/type_helpers.rb +++ b/lib/blueprinter/helpers/type_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter module TypeHelpers private diff --git a/lib/blueprinter/transformer.rb b/lib/blueprinter/transformer.rb index 0b5c06a5..aefb24df 100644 --- a/lib/blueprinter/transformer.rb +++ b/lib/blueprinter/transformer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter # @api private class Transformer diff --git a/lib/blueprinter/version.rb b/lib/blueprinter/version.rb index 6c32bce6..1f607521 100644 --- a/lib/blueprinter/version.rb +++ b/lib/blueprinter/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter - VERSION = '0.25.3'.freeze + VERSION = '1.0.0' end diff --git a/lib/blueprinter/view.rb b/lib/blueprinter/view.rb index 56df9481..bc550bbd 100644 --- a/lib/blueprinter/view.rb +++ b/lib/blueprinter/view.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter # @api private DefinitionPlaceholder = Struct.new :name, :view? diff --git a/lib/blueprinter/view_collection.rb b/lib/blueprinter/view_collection.rb index 56be69ac..a5f614e8 100644 --- a/lib/blueprinter/view_collection.rb +++ b/lib/blueprinter/view_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter # @api private class ViewCollection diff --git a/lib/generators/blueprinter/blueprint_generator.rb b/lib/generators/blueprinter/blueprint_generator.rb index 5edfdc91..8486cf26 100644 --- a/lib/generators/blueprinter/blueprint_generator.rb +++ b/lib/generators/blueprinter/blueprint_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Blueprinter module Generators class BlueprintGenerator < ::Rails::Generators::NamedBase diff --git a/lib/generators/blueprinter/templates/blueprint.rb b/lib/generators/blueprinter/templates/blueprint.rb index c07d6d5c..0635f424 100644 --- a/lib/generators/blueprinter/templates/blueprint.rb +++ b/lib/generators/blueprinter/templates/blueprint.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class <%= class_name %>Blueprint < Blueprinter::Base <% if identifier_symbol -%> <%= indent -%>identifier :<%= identifier_symbol %> diff --git a/lib/tasks/blueprinter_tasks.rake b/lib/tasks/blueprinter_tasks.rake deleted file mode 100644 index 3f06cd9b..00000000 --- a/lib/tasks/blueprinter_tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :blueprinter do -# # Task goes here -# end diff --git a/spec/activerecord_helper.rb b/spec/activerecord_helper.rb index c3a45662..88c9b10d 100644 --- a/spec/activerecord_helper.rb +++ b/spec/activerecord_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_record' require 'factories/model_factories.rb' diff --git a/spec/benchmark_helper.rb b/spec/benchmark_helper.rb index ee97180e..ede9daa5 100644 --- a/spec/benchmark_helper.rb +++ b/spec/benchmark_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'minitest/autorun' require 'minitest/benchmark' diff --git a/spec/benchmarks/active_record_big_o_test.rb b/spec/benchmarks/active_record_big_o_test.rb index 509c7bf3..ac2d163e 100644 --- a/spec/benchmarks/active_record_big_o_test.rb +++ b/spec/benchmarks/active_record_big_o_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'activerecord_helper' require 'benchmark_helper' require 'blueprinter/base' diff --git a/spec/benchmarks/active_record_ips_test.rb b/spec/benchmarks/active_record_ips_test.rb index fea1162f..57b27db7 100644 --- a/spec/benchmarks/active_record_ips_test.rb +++ b/spec/benchmarks/active_record_ips_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'activerecord_helper' require 'benchmark_helper' require 'blueprinter/base' diff --git a/spec/benchmarks/big_o_test.rb b/spec/benchmarks/big_o_test.rb index fb4611de..19e89420 100644 --- a/spec/benchmarks/big_o_test.rb +++ b/spec/benchmarks/big_o_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'benchmark_helper' require 'blueprinter/base' require 'ostruct' diff --git a/spec/benchmarks/ips_test.rb b/spec/benchmarks/ips_test.rb index d9224f40..00b00605 100644 --- a/spec/benchmarks/ips_test.rb +++ b/spec/benchmarks/ips_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'benchmark_helper' require 'blueprinter/base' require 'ostruct' diff --git a/spec/factories/model_factories.rb b/spec/factories/model_factories.rb index caddaaa4..f15cce34 100644 --- a/spec/factories/model_factories.rb +++ b/spec/factories/model_factories.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'factory_bot' FactoryBot.define do diff --git a/spec/generator_helper.rb b/spec/generator_helper.rb index 1eb31c5e..20ad247b 100644 --- a/spec/generator_helper.rb +++ b/spec/generator_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_record/railtie' # see https://github.com/rspec/rspec-rails/issues/1690 for vague hints require 'ammeter/init' require 'generators/shared' diff --git a/spec/generators/blueprint_generator_spec.rb b/spec/generators/blueprint_generator_spec.rb index 811fa7a8..1f085856 100644 --- a/spec/generators/blueprint_generator_spec.rb +++ b/spec/generators/blueprint_generator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'generator_helper' require 'generators/blueprinter/blueprint_generator' diff --git a/spec/generators/shared.rb b/spec/generators/shared.rb index ff778ff4..7c41550a 100644 --- a/spec/generators/shared.rb +++ b/spec/generators/shared.rb @@ -1,4 +1,5 @@ +# frozen_string_literal: true + RSpec.shared_examples "generated_file" do it { is_expected.to have_correct_syntax } end - diff --git a/spec/integrations/base_spec.rb b/spec/integrations/base_spec.rb index 50afbd29..78cc9636 100644 --- a/spec/integrations/base_spec.rb +++ b/spec/integrations/base_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'activerecord_helper' require 'ostruct' require_relative 'shared/base_render_examples' diff --git a/spec/integrations/shared/base_render_examples.rb b/spec/integrations/shared/base_render_examples.rb index 71f996fd..547c71db 100644 --- a/spec/integrations/shared/base_render_examples.rb +++ b/spec/integrations/shared/base_render_examples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + shared_examples 'Base::render' do context 'Given blueprint has ::field' do let(:result) { '{"first_name":"Meg","id":' + obj_id + '}' } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c615aef8..8a0215cb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'blueprinter' diff --git a/spec/units/configuration_spec.rb b/spec/units/configuration_spec.rb index 20ecb2de..c162dc5d 100644 --- a/spec/units/configuration_spec.rb +++ b/spec/units/configuration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'oj' require 'yajl' diff --git a/spec/units/date_time_formatter_spec.rb b/spec/units/date_time_formatter_spec.rb index e78ae577..8b49107d 100644 --- a/spec/units/date_time_formatter_spec.rb +++ b/spec/units/date_time_formatter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe '::DateTimeFormatter' do let(:formatter) { Blueprinter::DateTimeFormatter.new } let(:valid_date) { Date.new(1994, 3, 4) } diff --git a/spec/units/deprecation_spec.rb b/spec/units/deprecation_spec.rb index cbaaf06a..a1e6e3b5 100644 --- a/spec/units/deprecation_spec.rb +++ b/spec/units/deprecation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe 'Blueprinter::Deprecation' do describe '#report' do TEST_MESSAGE = "Test Message" diff --git a/spec/units/view_spec.rb b/spec/units/view_spec.rb index cc16cf67..22466aec 100644 --- a/spec/units/view_spec.rb +++ b/spec/units/view_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe '::View' do let(:view) { Blueprinter::View.new('Basic View') } let(:field) { MockField.new(:first_name) } From 5f1fb073a52fcc43aa017209e9dc54f458b3f353 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Thu, 5 Jan 2023 21:52:56 +0530 Subject: [PATCH 02/23] gem name changes --- .gitignore | 1 + README.md | 2 +- blueprinter.gemspec | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index e9d1c1a5..88e61c3a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Gemfile.lock .vscode .DS_Store tmp/ +*.gem diff --git a/README.md b/README.md index 8b06f7af..4115bbdc 100644 --- a/README.md +++ b/README.md @@ -974,7 +974,7 @@ Output: Add this line to your application's Gemfile: ```ruby -gem 'blueprinter' +gem 'blueprinter-rb' ``` And then execute: diff --git a/blueprinter.gemspec b/blueprinter.gemspec index b2361946..66987b9e 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -7,11 +7,11 @@ require "blueprinter/version" # Describe your gem and declare its dependencies: Gem::Specification.new do |s| - s.name = "blueprinter" + s.name = "blueprinter-rb" s.version = Blueprinter::VERSION - s.authors = ["Adam Hess", "Derek Carter"] - s.email = ["adamhess1991@gmail.com"] - s.homepage = "https://github.com/procore/blueprinter" + s.authors = ["Adam Hess", "Derek Carter", "Ritikesh G"] + s.email = ["ritikeshsisodiya@gmail.com"] + s.homepage = "https://github.com/blueprinter-ruby/blueprinter" s.summary = "Simple Fast Declarative Serialization Library" s.description = "Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant." s.license = "MIT" From f2ca9bcf9e1d57d114122a5e99ce5927df874d1d Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Fri, 27 Jan 2023 20:32:47 +0530 Subject: [PATCH 03/23] readme updates --- .gitignore | 3 ++- CHANGELOG.md | 3 +++ README.md | 56 ++------------------------------------------ blueprinter.gemspec | 9 +++---- blueprinter_logo.svg | 17 -------------- 5 files changed, 12 insertions(+), 76 deletions(-) delete mode 100644 blueprinter_logo.svg diff --git a/.gitignore b/.gitignore index 88e61c3a..fb22de81 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ Gemfile.lock .vscode .DS_Store tmp/ -*.gem +.ruby-version +.ruby-gemset diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f051a68..fd761ec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.0.0 - 2023/05/01 +* 🚀 [Official Release] Released [`blueprinter-rb`](https://rubygems.org/gems/blueprinter-rb) under a new organisation. More details can be found [here](https://github.com/procore/blueprinter/issues/288). + ## 0.25.3 - 2021/03/03 * 🐛 [BUGFIX] Fixes issue where fields and associations that are redefined by later views were not properly overwritten. See [#201](https://github.com/procore/blueprinter/pull/201) thanks to [@Berardpi](https://github.com/Berardpi). diff --git a/README.md b/README.md index 4115bbdc..8bd02d58 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,15 @@ - - # Blueprinter Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant. It heavily relies on the idea of `views` which, similar to Rails views, are ways of predefining output for data in different contexts. ## Documentation -Docs can be found [here](http://www.rubydoc.info/gems/blueprinter). +Docs can be found [here](http://www.rubydoc.info/gems/blueprinter-rb). ## Usage -
+
Basic ---- - If you have an object you would like serialized, simply create a blueprint. Say, for example, you have a User record with the following attributes `[:uuid, :email, :first_name, :last_name, :password, :address]`. You may define a simple blueprint like so: @@ -41,15 +37,12 @@ And the output would look like: "last_name": "Doe" } ``` - ----
Collections ---- You can also pass a collection object or an array to the render method. @@ -76,14 +69,12 @@ This will result in JSON that looks something like this: ] ``` ----
Renaming ---- You can rename the resulting JSON keys in both fields and associations by using the `name` option. @@ -107,14 +98,12 @@ This will result in JSON that looks something like this: } ``` ----
Views ---- You may define different outputs by utilizing views: ```ruby @@ -151,14 +140,12 @@ Output: } ``` ----
Identifiers ---- `identifier`s are used to specify a field or method name used as an identifier. Usually, this is something like `:id`. @@ -176,7 +163,6 @@ Blueprinter `identifier`s have a few properties that set them apart from `field` If either of the above two developer conveniences are not desired, you can simply create your identifier fields as regular `field`s. ----
@@ -184,7 +170,6 @@ If either of the above two developer conveniences are not desired, you can simpl
Root ---- You can also optionally pass in a root key to wrap your resulting json in: ```ruby @@ -215,14 +200,12 @@ Output: } ``` ----
Meta Attributes ---- You can additionally add meta-data to the json as well: ```ruby @@ -264,14 +247,12 @@ Output: ``` _NOTE:_ For meta attributes, a [root](#root) is mandatory. ----
Exclude Fields ---- You can specifically choose to exclude certain fields for specific views ```ruby @@ -325,14 +306,12 @@ class UserBlueprint < Blueprinter::Base end ``` ----
Associations ---- You may include associated objects. Say for example, a user has projects: ```ruby @@ -397,14 +376,12 @@ class DriverBlueprint < Blueprinter::Base end ``` ----
Default Association/Field Option ---- By default, an association or field that evaluates to `nil` is serialized as `nil`. A default serialized value can be specified as an option on the association or field for cases when the association/field could potentially evaluate to `nil`. You can also specify a global `field_default` or `association_default` in the Blueprinter config which will be used for all fields/associations that evaluate to nil. @@ -428,14 +405,12 @@ class UserBlueprint < Blueprinter::Base end ``` ----
default_if ---- Sometimes, you may want certain "empty" values to pass through to the default value. Blueprinter provides the ability to treat the following empty types as the default value (or `nil` if no default provided). @@ -463,14 +438,12 @@ class UserBlueprint < Blueprinter::Base end ``` ----
Supporting Dynamic Blueprints For Associations ---- When defining an association, we can dynamically evaluate the blueprint. This comes in handy when adding polymorphic associations, by allowing reuse of existing blueprints. ```ruby @@ -497,14 +470,12 @@ end ``` _NOTE:_ `taskable.blueprint` should return a valid Blueprint class. Currently, `has_many` is not supported because of the very nature of polymorphic associations. ----
Defining A Field Directly In The Blueprint ---- You can define a field directly in the Blueprint by passing it a block. This is especially useful if the object does not already have such an attribute or method defined, and you want to define it specifically for use with the Blueprint. This is done by passing `field` a block. The block also yields the object and any options that were passed from `render`. For example: @@ -532,14 +503,12 @@ Output: } ``` ----
Defining An Identifier Directly In The Blueprint ---- You can also pass a block to an identifier: @@ -565,14 +534,12 @@ Output: } ``` ----
Defining An Association Directly In The Blueprint ---- You can also pass a block to an association: @@ -610,14 +577,12 @@ Output: } ``` ----
Passing Additional Properties To #render ---- `render` takes an options hash which you can pass additional properties, allowing you to utilize those additional properties in the `field` block. For example: @@ -645,14 +610,12 @@ Output: } ``` ----
Conditional Fields ---- Both the `field` and the global Blueprinter Configuration supports `:if` and `:unless` options that can be used to serialize fields conditionally. @@ -675,14 +638,12 @@ end _NOTE:_ The field-level setting overrides the global config setting (for the field) if both are set. ----
Custom Formatting for Dates and Times ---- To define a custom format for a Date or DateTime field, include the option `datetime_format`. This global or field-level option can be either a string representing the associated `strftime` format, @@ -734,14 +695,12 @@ Output: _NOTE:_ The field-level setting overrides the global config setting (for the field) if both are set. ----
Transform Classes ---- Blueprinter provides the ability to specify `transform`s on views, which enable further processing and transforming of resulting view field hashes prior to serialization. @@ -800,13 +759,11 @@ end **Note: Any transforms specified on a per-blueprint or per-view level will override the `default_transformers` in the configuration.** ----
Configurable Extractors ---- Blueprinter gets a given objects' values from the fields definitions using extractor classes. You can substitute your own extractor class globally or per-field. @@ -852,13 +809,11 @@ Blueprinter.configure do |config| end ``` ----
Sorting Fields ---- By default the response sorts the keys by name. If you want the fields to be sorted in the order of definition, use the below configuration option. @@ -887,14 +842,12 @@ Output: } ``` ----
Deprecations ---- When functionality in Blueprinter is invoked, that has been deprecated, the default behavior is to write a deprecation notice to stderror. @@ -914,14 +867,12 @@ Blueprinter.configure do |config| end ``` ----
render_as_hash ---- Same as `render`, returns a Ruby Hash. @@ -940,14 +891,12 @@ Output: } ``` ----
render_as_json ---- Same as `render`, returns a Ruby Hash JSONified. This will call JSONify all keys and values. @@ -966,7 +915,6 @@ Output: } ``` ----
diff --git a/blueprinter.gemspec b/blueprinter.gemspec index 66987b9e..248ae6b8 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -9,20 +9,21 @@ require "blueprinter/version" Gem::Specification.new do |s| s.name = "blueprinter-rb" s.version = Blueprinter::VERSION - s.authors = ["Adam Hess", "Derek Carter", "Ritikesh G"] + s.authors = ["Ritikesh G"] s.email = ["ritikeshsisodiya@gmail.com"] s.homepage = "https://github.com/blueprinter-ruby/blueprinter" s.summary = "Simple Fast Declarative Serialization Library" s.description = "Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant." s.license = "MIT" - s.files = Dir["{app,config,db,lib}/**/*", "CHANGELOG.md", "MIT-LICENSE", "Rakefile", "README.md"] + s.files = Dir["{lib}/**/*", "MIT-LICENSE"] s.required_ruby_version = '>= 2.6.9' + s.add_runtime_dependency "oj", "~> 3.13" + s.add_runtime_dependency "yajl-ruby", "~> 1.4" + s.add_development_dependency "factory_bot", "~> 6.2" - s.add_development_dependency "oj", "~> 3.13" - s.add_development_dependency "yajl-ruby", "~> 1.4" s.add_development_dependency "pry", "~> 0.14" s.add_development_dependency "activerecord", "~> 7.0" s.add_development_dependency "rspec", "~> 3.12" diff --git a/blueprinter_logo.svg b/blueprinter_logo.svg deleted file mode 100644 index c5b65fd7..00000000 --- a/blueprinter_logo.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - Blueprinter_option3 - Created with Sketch. - - - - - - - - - - - - \ No newline at end of file From 59855696f739e203feb878e216b4a2382482205a Mon Sep 17 00:00:00 2001 From: nametoolong Date: Mon, 30 Jan 2023 21:33:30 +0800 Subject: [PATCH 04/23] Reduce object allocations in fields calculation (#5) --- lib/blueprinter/view_collection.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/blueprinter/view_collection.rb b/lib/blueprinter/view_collection.rb index a5f614e8..4248e2f4 100644 --- a/lib/blueprinter/view_collection.rb +++ b/lib/blueprinter/view_collection.rb @@ -28,7 +28,9 @@ def fields_for(view_name) fields, excluded_fields = sortable_fields(view_name) sorted_fields = sort_by_definition ? sort_by_def(view_name, fields) : fields.values.sort_by(&:name) - (identifier_fields + sorted_fields).reject { |field| excluded_fields.include?(field.name) } + (identifier_fields + sorted_fields).tap do |fields| + fields.reject! { |field| excluded_fields.include?(field.name) } + end end def transformers(view_name) @@ -49,15 +51,15 @@ def identifier_fields # @return [Array<(Hash, Hash)>] fields, excluded_fields def sortable_fields(view_name) excluded_fields = {} - fields = views[:default].fields + fields = views[:default].fields.clone views[view_name].included_view_names.each do |included_view_name| next if view_name == included_view_name view_fields, view_excluded_fields = sortable_fields(included_view_name) - fields = merge_fields(fields, view_fields) + fields.merge!(view_fields) excluded_fields.merge!(view_excluded_fields) end - fields = merge_fields(fields, views[view_name].fields) + fields.merge!(views[view_name].fields) unless view_name == :default views[view_name].excluded_field_names.each { |name| excluded_fields[name] = nil } @@ -82,9 +84,5 @@ def add_to_ordered_fields(ordered_fields, definition, fields, view_name_filter = ordered_fields[definition.name] = fields[definition.name] end end - - def merge_fields(source_fields, included_fields) - source_fields.merge included_fields - end end end From 9bdb84d49a919b9638d7c19d0820abeef7294e93 Mon Sep 17 00:00:00 2001 From: Todd D Nestor Date: Tue, 31 Jan 2023 00:41:33 -0800 Subject: [PATCH 05/23] Run tests in Github Actions (#4) * Run tests in Github Actions * Update github action configuration Co-authored-by: Ritikesh * Update ruby versions we run tests against, temporarily run tests on this branch too * do not use ruby 2.6 in tests * Update required ruby version * Try not locking activerecord to as recent a version and run tests in ruby 2.6.9 and 3.2 * Remove this branch from those that trigger tests * Update blueprinter.gemspec --------- Co-authored-by: Ritikesh --- .github/workflows/tests.yml | 28 ++++++++++++++++++++++++++++ blueprinter.gemspec | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..d78e0603 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,28 @@ +name: rspec + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read +jobs: + test: + + runs-on: ubuntu-latest + + strategy: + matrix: + ruby-version: [2.6.9, 2.7, 3.0, 3.1, 3.2] + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Run tests + run: bundle exec rake diff --git a/blueprinter.gemspec b/blueprinter.gemspec index 248ae6b8..7a22a58a 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |s| s.add_development_dependency "factory_bot", "~> 6.2" s.add_development_dependency "pry", "~> 0.14" - s.add_development_dependency "activerecord", "~> 7.0" + s.add_development_dependency "activerecord", ">= 5.2" s.add_development_dependency "rspec", "~> 3.12" s.add_development_dependency "rspec-rails", "~> 6.0" s.add_development_dependency "sqlite3", "~> 1.5" From bba5baf4a99ec2539214c238ec2396e02974e21a Mon Sep 17 00:00:00 2001 From: Todd D Nestor Date: Tue, 31 Jan 2023 01:00:12 -0800 Subject: [PATCH 06/23] Add gem version badge to README pointed at new gem (#7) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8bd02d58..57eb29d8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Gem Version](https://badge.fury.io/rb/blueprinter-rb.svg)](https://badge.fury.io/rb/blueprinter-rb) + # Blueprinter Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant. From e4fed251816c03c77f24bb15afc24e30a678dd87 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Tue, 31 Jan 2023 14:37:01 +0530 Subject: [PATCH 07/23] Add a workflow status badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 57eb29d8..833731be 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Gem Version](https://badge.fury.io/rb/blueprinter-rb.svg)](https://badge.fury.io/rb/blueprinter-rb) +![Tests](https://github.com/blueprinter-ruby/blueprinter/actions/workflows/tests.yml/badge.svg) # Blueprinter Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant. From beaa3958db26df165b80ce59d1cedae4f79d2802 Mon Sep 17 00:00:00 2001 From: Todd D Nestor Date: Fri, 3 Feb 2023 03:40:20 -0800 Subject: [PATCH 08/23] Make array like classes configurable (#6) * Allow configuration of array-like classes * update README to include information about the array_like_classes configuration option * do not persist vehicles to db in tests * Consolidate array-like logic and add test case for non-configured array-like class * memoize the array_like_classes * Increment version and update CHANGELOG * Apply suggestions from code review --------- Co-authored-by: Ritikesh --- CHANGELOG.md | 6 ++- README.md | 18 +++++++++ lib/blueprinter/configuration.rb | 11 ++++- lib/blueprinter/helpers/type_helpers.rb | 8 ++-- lib/blueprinter/version.rb | 2 +- spec/integrations/base_spec.rb | 54 +++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd761ec2..81af084e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -## 1.0.0 - 2023/05/01 +## 1.1.0 - 2023/02/02 +* 🚀 [FEATURE] Allow configuring custom array-like classes to be treated as collections when serializing. More details can be found [here](https://github.com/blueprinter-ruby/blueprinter/pull/6). Thanks to [@toddnestor](https://github.com/toddnestor). +* 💅 [ENHANCEMENT] Reduce object allocations in fields calculations to save some memory. More details can be found [here](https://github.com/blueprinter-ruby/blueprinter/pull/5). Thanks to [@nametoolong](https://github.com/nametoolong). + +## 1.0.0 - 2023/01/05 * 🚀 [Official Release] Released [`blueprinter-rb`](https://rubygems.org/gems/blueprinter-rb) under a new organisation. More details can be found [here](https://github.com/procore/blueprinter/issues/288). ## 0.25.3 - 2021/03/03 diff --git a/README.md b/README.md index 833731be..8f554273 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,24 @@ This will result in JSON that looks something like this: ] ``` + +You can also configure other classes to be treated like collections. For example, if you are using Mongoid, you can configure it to treat `Mongoid::Criteria` objects as collections: + +```ruby +Blueprinter.configure do |config| + config.custom_array_like_classes = [Mongoid::Criteria] +end +``` + +Or if you wanted it to treat the `Set` class as a collection: + +```ruby +Blueprinter.configure do |config| + config.custom_array_like_classes = [Set] +end +``` + +---
diff --git a/lib/blueprinter/configuration.rb b/lib/blueprinter/configuration.rb index 3ceef245..36d105e6 100644 --- a/lib/blueprinter/configuration.rb +++ b/lib/blueprinter/configuration.rb @@ -2,7 +2,7 @@ module Blueprinter class Configuration - attr_accessor :association_default, :datetime_format, :deprecations, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default, :default_transformers + attr_accessor :association_default, :datetime_format, :deprecations, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default, :default_transformers, :custom_array_like_classes VALID_CALLABLES = %i(if unless).freeze @@ -18,6 +18,15 @@ def initialize @unless = nil @extractor_default = AutoExtractor @default_transformers = [] + @custom_array_like_classes = [] + end + + def array_like_classes + @array_like_classes ||= [ + Array, + defined?(ActiveRecord::Relation) && ActiveRecord::Relation, + *custom_array_like_classes + ].compact end def jsonify(blob) diff --git a/lib/blueprinter/helpers/type_helpers.rb b/lib/blueprinter/helpers/type_helpers.rb index dde3d8d6..632463ac 100644 --- a/lib/blueprinter/helpers/type_helpers.rb +++ b/lib/blueprinter/helpers/type_helpers.rb @@ -3,13 +3,11 @@ module Blueprinter module TypeHelpers private - def active_record_relation?(object) - !!(defined?(ActiveRecord::Relation) && - object.is_a?(ActiveRecord::Relation)) - end def array_like?(object) - object.is_a?(Array) || active_record_relation?(object) + Blueprinter.configuration.array_like_classes.any? do |klass| + object.is_a?(klass) + end end end end diff --git a/lib/blueprinter/version.rb b/lib/blueprinter/version.rb index 1f607521..5a9fdafc 100644 --- a/lib/blueprinter/version.rb +++ b/lib/blueprinter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Blueprinter - VERSION = '1.0.0' + VERSION = '1.1.0' end diff --git a/spec/integrations/base_spec.rb b/spec/integrations/base_spec.rb index 78cc9636..e83a7961 100644 --- a/spec/integrations/base_spec.rb +++ b/spec/integrations/base_spec.rb @@ -58,6 +58,30 @@ end end + context 'Given passed object is array-like' do + let(:blueprint) { blueprint_with_block } + let(:additional_object) { OpenStruct.new(obj_hash.merge(id: 2)) } + let(:obj) { Set.new([object_with_attributes, additional_object]) } + + context 'and is an instance of a configured array-like class' do + before do + reset_blueprinter_config! + Blueprinter.configure { |config| config.custom_array_like_classes = [Set] } + end + after { reset_blueprinter_config! } + + it 'should return the expected array of hashes' do + should eq('[{"id":1,"position_and_company":"Manager at Procore"},{"id":2,"position_and_company":"Manager at Procore"}]') + end + end + + context 'and is not an instance of a configured array-like class' do + it 'should raise an error' do + expect { blueprint.render(obj) }.to raise_error(NoMethodError) + end + end + end + context 'Inside Rails project' do include FactoryBot::Syntax::Methods let(:obj) { create(:user) } @@ -383,6 +407,36 @@ def extract(association_name, object, _local_options, _options={}) end end end + + context 'Given passed object is an instance of a configured array-like class' do + let(:blueprint) do + Class.new(Blueprinter::Base) do + identifier :id + fields :make + end + end + let(:vehicle1) { build(:vehicle, id: 1) } + let(:vehicle2) { build(:vehicle, id: 2, make: 'Mediocre Car') } + let(:vehicle3) { build(:vehicle, id: 3, make: 'Terrible Car') } + let(:vehicles) { [vehicle1, vehicle2, vehicle3] } + let(:obj) { Set.new(vehicles) } + let(:result) do + vehicles_json = vehicles.map do |vehicle| + "{\"id\":#{vehicle.id},\"make\":\"#{vehicle.make}\"}" + end.join(',') + "[#{vehicles_json}]" + end + + before do + reset_blueprinter_config! + Blueprinter.configure do |config| + config.custom_array_like_classes = [Set] + end + end + after { reset_blueprinter_config! } + + it('returns the expected result') { should eq(result) } + end end end describe '::render_as_hash' do From 547708f94e4ae7589ba155411fd63fe129e08852 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Fri, 3 Feb 2023 17:27:20 +0530 Subject: [PATCH 09/23] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fb22de81..46a43168 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ Gemfile.lock tmp/ .ruby-version .ruby-gemset +*.gem From 0093c3526fe8c5820b4fe705e552a31e2946b2ad Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Mon, 6 Feb 2023 21:17:22 +0530 Subject: [PATCH 10/23] change runtime dependencies to dev dependencies (#9) fixes #8 --- CHANGELOG.md | 3 +++ blueprinter.gemspec | 4 ++-- lib/blueprinter/version.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81af084e..17559f15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.1.1 - 2023/02/06 +* 🐛 [BUGFIX] Fix accidental hard dependency requirement of yajl and oj in gemspec from a routine cleanup commit + ## 1.1.0 - 2023/02/02 * 🚀 [FEATURE] Allow configuring custom array-like classes to be treated as collections when serializing. More details can be found [here](https://github.com/blueprinter-ruby/blueprinter/pull/6). Thanks to [@toddnestor](https://github.com/toddnestor). * 💅 [ENHANCEMENT] Reduce object allocations in fields calculations to save some memory. More details can be found [here](https://github.com/blueprinter-ruby/blueprinter/pull/5). Thanks to [@nametoolong](https://github.com/nametoolong). diff --git a/blueprinter.gemspec b/blueprinter.gemspec index 7a22a58a..f612cfa1 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -20,8 +20,8 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.6.9' - s.add_runtime_dependency "oj", "~> 3.13" - s.add_runtime_dependency "yajl-ruby", "~> 1.4" + s.add_development_dependency "oj", "~> 3.13" + s.add_development_dependency "yajl-ruby", "~> 1.4" s.add_development_dependency "factory_bot", "~> 6.2" s.add_development_dependency "pry", "~> 0.14" diff --git a/lib/blueprinter/version.rb b/lib/blueprinter/version.rb index 5a9fdafc..cd3a79ea 100644 --- a/lib/blueprinter/version.rb +++ b/lib/blueprinter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Blueprinter - VERSION = '1.1.0' + VERSION = '1.1.1' end From 02ed627cf9bd736994dadb65acf1c17f62981e66 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Tue, 7 Feb 2023 01:14:51 +0530 Subject: [PATCH 11/23] rubocop workflow (#10) * create a rubocop workflow * Update rubocop.yml * rubocop V1 * update workflow files * Update rubocop.yml * Update rubocop.yml * Update rubocop.yml * final updates * Update rubocop.yml * final updates * lock rubocop version * update description of gem * Update lib/blueprinter/extractors/block_extractor.rb --- .github/workflows/rubocop.yml | 21 ++++ .github/workflows/tests.yml | 5 - .rubocop.yml | 26 +++++ CHANGELOG.md | 3 + Gemfile | 11 +- README.md | 1 + Rakefile | 2 + blueprinter.gemspec | 35 +++--- lib/blueprinter/base.rb | 23 ++-- lib/blueprinter/configuration.rb | 5 +- lib/blueprinter/deprecation.rb | 6 +- lib/blueprinter/empty_types.rb | 13 +-- lib/blueprinter/extractor.rb | 8 +- .../extractors/association_extractor.rb | 5 +- lib/blueprinter/extractors/block_extractor.rb | 2 +- .../extractors/public_send_extractor.rb | 2 +- lib/blueprinter/field.rb | 100 ++++++++++-------- .../formatters/date_time_formatter.rb | 2 +- lib/blueprinter/helpers/base_helpers.rb | 28 ++--- lib/blueprinter/transformer.rb | 4 +- lib/blueprinter/version.rb | 2 +- lib/blueprinter/view.rb | 12 +-- lib/blueprinter/view_collection.rb | 17 +-- .../blueprinter/blueprint_generator.rb | 83 ++++++--------- spec/integrations/base_spec.rb | 2 +- 25 files changed, 232 insertions(+), 186 deletions(-) create mode 100644 .github/workflows/rubocop.yml create mode 100644 .rubocop.yml diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml new file mode 100644 index 00000000..5be5b811 --- /dev/null +++ b/.github/workflows/rubocop.yml @@ -0,0 +1,21 @@ +name: "rubocop" +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.6.9' + bundler-cache: true + - name: Rubocop + # yard's rubocop.yml is interfering with the execution when using bundle exec + # without bundle exec github action isn't able to detect the executable + run: bundle exec rubocop --config ./.rubocop.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d78e0603..7d6ef4f5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,22 +1,17 @@ name: rspec - on: push: branches: [ "master" ] pull_request: branches: [ "master" ] - permissions: contents: read jobs: test: - runs-on: ubuntu-latest - strategy: matrix: ruby-version: [2.6.9, 2.7, 3.0, 3.1, 3.2] - steps: - uses: actions/checkout@v3 - name: Set up Ruby diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..e3160f82 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,26 @@ +AllCops: + TargetRubyVersion: 2.6.9 + NewCops: enable + Exclude: + - 'lib/generators/**/*' + - 'tmp/**/*' + - 'spec/**/*' + - 'vendor/**/*' # added by github actions + +Style/Documentation: + Enabled: false + +Style/SafeNavigation: + Enabled: false + +Layout/LineLength: + Max: 175 + +Lint/MissingSuper: + Enabled: false + +Metrics/MethodLength: + Max: 15 + +Metrics/AbcSize: + Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 17559f15..729576f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.1.2 - 2023/02/06 +* 💅 [ENHANCEMENT] Introduce rubocop and add a Github action for it + ## 1.1.1 - 2023/02/06 * 🐛 [BUGFIX] Fix accidental hard dependency requirement of yajl and oj in gemspec from a routine cleanup commit diff --git a/Gemfile b/Gemfile index fd0b6ce2..95397caa 100644 --- a/Gemfile +++ b/Gemfile @@ -12,5 +12,12 @@ gemspec # Git. Remember to move these dependencies to your gemspec before releasing # your gem to rubygems.org. -# To use a debugger -# gem 'byebug', group: [:development, :test] +gem 'activerecord', '>= 5.2' +gem 'ammeter', '~> 1.1' +gem 'factory_bot', '~> 6.2' +gem 'pry', '~> 0.14' +gem 'rspec', '~> 3.12' +gem 'rspec-rails', '~> 6.0' +gem 'rubocop', '~> 1.44' +gem 'sqlite3', '~> 1.5' +gem 'yard', '~> 0.9' diff --git a/README.md b/README.md index 8f554273..295dfa53 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Gem Version](https://badge.fury.io/rb/blueprinter-rb.svg)](https://badge.fury.io/rb/blueprinter-rb) ![Tests](https://github.com/blueprinter-ruby/blueprinter/actions/workflows/tests.yml/badge.svg) +![rubocop](https://github.com/blueprinter-ruby/blueprinter/actions/workflows/rubocop.yml/badge.svg) # Blueprinter Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant. diff --git a/Rakefile b/Rakefile index 1ba485b5..de2306b4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rdoc/task' require 'bundler/gem_tasks' require 'rake/testtask' diff --git a/blueprinter.gemspec b/blueprinter.gemspec index f612cfa1..db69eb22 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -1,34 +1,29 @@ # frozen_string_literal: true -$:.push File.expand_path("../lib", __FILE__) +$LOAD_PATH.push File.expand_path('lib', __dir__) # Maintain your gem's version: -require "blueprinter/version" +require 'blueprinter/version' # Describe your gem and declare its dependencies: Gem::Specification.new do |s| - s.name = "blueprinter-rb" + s.name = 'blueprinter-rb' s.version = Blueprinter::VERSION - s.authors = ["Ritikesh G"] - s.email = ["ritikeshsisodiya@gmail.com"] - s.homepage = "https://github.com/blueprinter-ruby/blueprinter" - s.summary = "Simple Fast Declarative Serialization Library" - s.description = "Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant." - s.license = "MIT" + s.authors = ['Ritikesh G'] + s.email = ['ritikeshsisodiya@gmail.com'] + s.homepage = 'https://github.com/blueprinter-ruby/blueprinter' + s.summary = 'Simple Fast Declarative Serialization Library' + s.description = 'Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks' \ + 'them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other' \ + 'serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant.' + s.license = 'MIT' - s.files = Dir["{lib}/**/*", "MIT-LICENSE"] + s.files = Dir['{lib}/**/*', 'MIT-LICENSE', 'README.md'] s.required_ruby_version = '>= 2.6.9' - s.add_development_dependency "oj", "~> 3.13" - s.add_development_dependency "yajl-ruby", "~> 1.4" + s.add_development_dependency 'oj', '~> 3.13' + s.add_development_dependency 'yajl-ruby', '~> 1.4' - s.add_development_dependency "factory_bot", "~> 6.2" - s.add_development_dependency "pry", "~> 0.14" - s.add_development_dependency "activerecord", ">= 5.2" - s.add_development_dependency "rspec", "~> 3.12" - s.add_development_dependency "rspec-rails", "~> 6.0" - s.add_development_dependency "sqlite3", "~> 1.5" - s.add_development_dependency "yard", "~> 0.9" - s.add_development_dependency "ammeter", "~> 1.1" + s.metadata['rubygems_mfa_required'] = 'true' end diff --git a/lib/blueprinter/base.rb b/lib/blueprinter/base.rb index 3943a06f..acb4182e 100644 --- a/lib/blueprinter/base.rb +++ b/lib/blueprinter/base.rb @@ -60,7 +60,7 @@ def self.identifier(method, name: method, extractor: Blueprinter.configuration.e name, extractor, self, - block: block, + block: block ) end @@ -125,7 +125,7 @@ def self.field(method, options = {}, &block) options.fetch(:name) { method }, options.fetch(:extractor) { Blueprinter.configuration.extractor_default.new }, self, - options.merge(block: block), + options.merge(block: block) ) end @@ -165,7 +165,7 @@ def self.association(method, options = {}, &block) method, options.merge( association: true, - extractor: options.fetch(:extractor) { AssociationExtractor.new }, + extractor: options.fetch(:extractor) { AssociationExtractor.new } ), &block ) @@ -254,9 +254,7 @@ def self.render_as_json(object, options = {}) # # @api private def self.prepare(object, view_name:, local_options:, root: nil, meta: nil) - unless view_collection.has_view? view_name - raise BlueprinterError, "View '#{view_name}' is not defined" - end + raise BlueprinterError, "View '#{view_name}' is not defined" unless view_collection.view? view_name data = prepare_data(object, view_name, local_options) prepend_root_and_meta(data, root, meta) @@ -281,7 +279,6 @@ def self.fields(*field_names) end end - # Specify one transformer to be included for serialization. # Takes a class which extends Blueprinter::Transformer # @@ -317,7 +314,6 @@ def self.transform(transformer) current_view.add_transformer(transformer) end - # Specify another view that should be mixed into the current view. # # @param view_name [Symbol] the view to mix into the current view. @@ -340,7 +336,6 @@ def self.include_view(view_name) current_view.include_view(view_name) end - # Specify additional views that should be mixed into the current view. # # @param view_name [Array] the views to mix into the current view. @@ -363,12 +358,10 @@ def self.include_view(view_name) # # @return [Array] an array of view names. - def self.include_views(*view_names) current_view.include_views(view_names) end - # Exclude a field that was mixed into the current view. # # @param field_name [Symbol] the field to exclude from the current view. @@ -446,13 +439,13 @@ def self.view(view_name) # end # end # - # ExampleBlueprint.has_view?(:custom) => true - # ExampleBlueprint.has_view?(:doesnt_exist) => false + # ExampleBlueprint.view?(:custom) => true + # ExampleBlueprint.view?(:doesnt_exist) => false # # @return [Boolean] a boolean value indicating if the view is # supported by this Blueprint. - def self.has_view?(view_name) - view_collection.has_view? view_name + def self.view?(view_name) + view_collection.view? view_name end end end diff --git a/lib/blueprinter/configuration.rb b/lib/blueprinter/configuration.rb index 36d105e6..050d07a9 100644 --- a/lib/blueprinter/configuration.rb +++ b/lib/blueprinter/configuration.rb @@ -2,9 +2,10 @@ module Blueprinter class Configuration - attr_accessor :association_default, :datetime_format, :deprecations, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default, :default_transformers, :custom_array_like_classes + attr_accessor :association_default, :datetime_format, :deprecations, :field_default, :generator, :if, :method, + :sort_fields_by, :unless, :extractor_default, :default_transformers, :custom_array_like_classes - VALID_CALLABLES = %i(if unless).freeze + VALID_CALLABLES = %i[if unless].freeze def initialize @deprecations = :stderror diff --git a/lib/blueprinter/deprecation.rb b/lib/blueprinter/deprecation.rb index 85f95331..ae6cdd64 100644 --- a/lib/blueprinter/deprecation.rb +++ b/lib/blueprinter/deprecation.rb @@ -4,8 +4,8 @@ module Blueprinter class Deprecation class << self - VALID_BEHAVIORS = %i(silence stderror raise).freeze - MESSAGE_PREFIX = "[DEPRECATION::WARNING] Blueprinter:" + VALID_BEHAVIORS = %i[silence stderror raise].freeze + MESSAGE_PREFIX = '[DEPRECATION::WARNING] Blueprinter:' def report(message) full_msg = qualified_message(message) @@ -28,7 +28,7 @@ def qualified_message(message) def behavior configured = Blueprinter.configuration.deprecations - return configured unless !VALID_BEHAVIORS.include?(configured) + return configured if VALID_BEHAVIORS.include?(configured) :stderror end diff --git a/lib/blueprinter/empty_types.rb b/lib/blueprinter/empty_types.rb index a3903fde..5a5b24ce 100644 --- a/lib/blueprinter/empty_types.rb +++ b/lib/blueprinter/empty_types.rb @@ -3,12 +3,13 @@ require_relative 'helpers/type_helpers' module Blueprinter - EMPTY_COLLECTION = "empty_collection" - EMPTY_HASH = "empty_hash" - EMPTY_STRING = "empty_string" + EMPTY_COLLECTION = 'empty_collection' + EMPTY_HASH = 'empty_hash' + EMPTY_STRING = 'empty_string' module EmptyTypes include TypeHelpers + private def use_default_value?(value, empty_type) @@ -20,11 +21,11 @@ def use_default_value?(value, empty_type) when Blueprinter::EMPTY_HASH value.is_a?(Hash) && value.empty? when Blueprinter::EMPTY_STRING - value.to_s == "" + value.to_s == '' else Blueprinter::Deprecation.report( - "Invalid empty type '#{empty_type}' received. Blueprinter will raise an error in the next major version."\ - "Must be one of [nil, Blueprinter::EMPTY_COLLECTION, Blueprinter::EMPTY_HASH, Blueprinter::EMPTY_STRING]" + "Invalid empty type '#{empty_type}' received. Blueprinter will raise an error in the next major version." \ + 'Must be one of [nil, Blueprinter::EMPTY_COLLECTION, Blueprinter::EMPTY_HASH, Blueprinter::EMPTY_STRING]' ) end end diff --git a/lib/blueprinter/extractor.rb b/lib/blueprinter/extractor.rb index 9e7009d4..373c56eb 100644 --- a/lib/blueprinter/extractor.rb +++ b/lib/blueprinter/extractor.rb @@ -2,12 +2,12 @@ module Blueprinter class Extractor - def extract(_field_name, _object, _local_options, _options={}) - fail NotImplementedError, "An Extractor must implement #extract" + def extract(_field_name, _object, _local_options, _options = {}) + raise NotImplementedError, 'An Extractor must implement #extract' end - def self.extract(field_name, object, local_options, options={}) - self.new.extract(field_name, object, local_options, options) + def self.extract(field_name, object, local_options, options = {}) + new.extract(field_name, object, local_options, options) end end end diff --git a/lib/blueprinter/extractors/association_extractor.rb b/lib/blueprinter/extractors/association_extractor.rb index 0f77331d..ba100c93 100644 --- a/lib/blueprinter/extractors/association_extractor.rb +++ b/lib/blueprinter/extractors/association_extractor.rb @@ -9,12 +9,13 @@ def initialize @extractor = Blueprinter.configuration.extractor_default.new end - def extract(association_name, object, local_options, options={}) - options_without_default = options.reject { |k,_| k == :default || k == :default_if } + def extract(association_name, object, local_options, options = {}) + options_without_default = options.reject { |k, _| %i[default default_if].include?(k) } # Merge in assocation options hash local_options = local_options.merge(options[:options]) if options[:options].is_a?(Hash) value = @extractor.extract(association_name, object, local_options, options_without_default) return default_value(options) if use_default_value?(value, options[:default_if]) + view = options[:view] || :default blueprint = association_blueprint(options[:blueprint], value) blueprint.prepare(value, view_name: view, local_options: local_options) diff --git a/lib/blueprinter/extractors/block_extractor.rb b/lib/blueprinter/extractors/block_extractor.rb index 043c34b1..925d8e8e 100644 --- a/lib/blueprinter/extractors/block_extractor.rb +++ b/lib/blueprinter/extractors/block_extractor.rb @@ -3,7 +3,7 @@ module Blueprinter # @api private class BlockExtractor < Extractor - def extract(field_name, object, local_options, options = {}) + def extract(_field_name, object, local_options, options = {}) options[:block].call(object, local_options) end end diff --git a/lib/blueprinter/extractors/public_send_extractor.rb b/lib/blueprinter/extractors/public_send_extractor.rb index d0401352..d3a0c320 100644 --- a/lib/blueprinter/extractors/public_send_extractor.rb +++ b/lib/blueprinter/extractors/public_send_extractor.rb @@ -3,7 +3,7 @@ module Blueprinter # @api private class PublicSendExtractor < Extractor - def extract(field_name, object, local_options, options = {}) + def extract(field_name, object, _local_options, _options = {}) object.public_send(field_name) end end diff --git a/lib/blueprinter/field.rb b/lib/blueprinter/field.rb index 32e3b07a..2b783cf5 100644 --- a/lib/blueprinter/field.rb +++ b/lib/blueprinter/field.rb @@ -1,65 +1,71 @@ # frozen_string_literal: true # @api private -class Blueprinter::Field - attr_reader :method, :name, :extractor, :options, :blueprint - def initialize(method, name, extractor, blueprint, options = {}) - @method = method - @name = name - @extractor = extractor - @blueprint = blueprint - @options = options - end +module Blueprinter + class Field + attr_reader :method, :name, :extractor, :options, :blueprint - def extract(object, local_options) - extractor.extract(method, object, local_options, options) - end + def initialize(method, name, extractor, blueprint, options = {}) + @method = method + @name = name + @extractor = extractor + @blueprint = blueprint + @options = options + end - def skip?(field_name, object, local_options) - return true if if_callable && !if_callable.call(field_name, object, local_options) - unless_callable && unless_callable.call(field_name, object, local_options) - end + def extract(object, local_options) + extractor.extract(method, object, local_options, options) + end - private + def skip?(field_name, object, local_options) + return true if if_callable && !if_callable.call(field_name, object, local_options) - def if_callable - return @if_callable if defined?(@if_callable) - @if_callable = callable_from(:if) - end + unless_callable && unless_callable.call(field_name, object, local_options) + end - def unless_callable - return @unless_callable if defined?(@unless_callable) - @unless_callable = callable_from(:unless) - end + private - def callable_from(condition) - callable = old_callable_from(condition) + def if_callable + return @if_callable if defined?(@if_callable) - if callable && callable.arity == 2 - Blueprinter::Deprecation.report("`:#{condition}` conditions now expects 3 arguments instead of 2.") - ->(_field_name, obj, options) { callable.call(obj, options) } - else - callable + @if_callable = callable_from(:if) + end + + def unless_callable + return @unless_callable if defined?(@unless_callable) + + @unless_callable = callable_from(:unless) + end + + def callable_from(condition) + callable = old_callable_from(condition) + + if callable && callable.arity == 2 + Blueprinter::Deprecation.report("`:#{condition}` conditions now expects 3 arguments instead of 2.") + ->(_field_name, obj, options) { callable.call(obj, options) } + else + callable + end end - end - def old_callable_from(condition) - config = Blueprinter.configuration + def old_callable_from(condition) + config = Blueprinter.configuration - # Use field-level callable, or when not defined, try global callable - tmp = if options.key?(condition) - options.fetch(condition) - elsif config.valid_callable?(condition) - config.public_send(condition) - end + # Use field-level callable, or when not defined, try global callable + tmp = if options.key?(condition) + options.fetch(condition) + elsif config.valid_callable?(condition) + config.public_send(condition) + end - return false unless tmp + return false unless tmp - case tmp - when Proc then tmp - when Symbol then blueprint.method(tmp) - else - raise ArgumentError, "#{tmp.class} is passed to :#{condition}" + case tmp + when Proc then tmp + when Symbol then blueprint.method(tmp) + else + raise ArgumentError, "#{tmp.class} is passed to :#{condition}" + end end end end diff --git a/lib/blueprinter/formatters/date_time_formatter.rb b/lib/blueprinter/formatters/date_time_formatter.rb index a24c0fc9..e63cdaa0 100644 --- a/lib/blueprinter/formatters/date_time_formatter.rb +++ b/lib/blueprinter/formatters/date_time_formatter.rb @@ -26,7 +26,7 @@ def format_datetime(value, field_format) when Proc then format.call(value) when String then value.strftime(format) else - raise InvalidDateTimeFormatterError, 'Cannot format DateTime object with invalid formatter: #{format.class}' + raise InvalidDateTimeFormatterError, "Cannot format DateTime object with invalid formatter: #{format.class}" end end end diff --git a/lib/blueprinter/helpers/base_helpers.rb b/lib/blueprinter/helpers/base_helpers.rb index cb770a9c..f87960cc 100644 --- a/lib/blueprinter/helpers/base_helpers.rb +++ b/lib/blueprinter/helpers/base_helpers.rb @@ -35,7 +35,8 @@ def prepare_data(object, view_name, local_options) def prepend_root_and_meta(data, root, meta) return data unless root - ret = {root => data} + + ret = { root => data } meta ? ret.merge!(meta: meta) : ret end @@ -46,6 +47,7 @@ def inherited(subclass) def object_to_hash(object, view_name:, local_options:) result_hash = view_collection.fields_for(view_name).each_with_object({}) do |field, hash| next if field.skip?(field.name, object, local_options) + hash[field.name] = field.extract(object, local_options) end view_collection.transformers(view_name).each do |transformer| @@ -59,9 +61,9 @@ def validate_root_and_meta!(root, meta) when String, Symbol # no-op when NilClass - raise BlueprinterError, "meta requires a root to be passed" if meta + raise BlueprinterError, 'meta requires a root to be passed' if meta else - raise BlueprinterError, "root should be one of String, Symbol, NilClass" + raise BlueprinterError, 'root should be one of String, Symbol, NilClass' end end @@ -71,10 +73,10 @@ def dynamic_blueprint?(blueprint) def validate_blueprint!(blueprint, method) validate_presence_of_blueprint!(blueprint) - unless dynamic_blueprint?(blueprint) - validate_blueprint_has_ancestors!(blueprint, method) - validate_blueprint_has_blueprinter_base_ancestor!(blueprint, method) - end + return if dynamic_blueprint?(blueprint) + + validate_blueprint_has_ancestors!(blueprint, method) + validate_blueprint_has_blueprinter_base_ancestor!(blueprint, method) end def validate_presence_of_blueprint!(blueprint) @@ -86,10 +88,10 @@ def validate_blueprint_has_ancestors!(blueprint, association_name) # it means it, at the very least, does not have Blueprinter::Base as # one of its ancestor classes (e.g: Hash) and thus an error should # be raised. - unless blueprint.respond_to?(:ancestors) - raise BlueprinterError, "Blueprint provided for #{association_name} "\ + return if blueprint.respond_to?(:ancestors) + + raise BlueprinterError, "Blueprint provided for #{association_name} " \ 'association is not valid.' - end end def validate_blueprint_has_blueprinter_base_ancestor!(blueprint, association_name) @@ -98,9 +100,9 @@ def validate_blueprint_has_blueprinter_base_ancestor!(blueprint, association_nam return if blueprint.ancestors.include? Blueprinter::Base # Raise error describing what's wrong. - raise BlueprinterError, "Class #{blueprint.name} does not inherit from "\ - 'Blueprinter::Base and is not a valid Blueprinter '\ - "for #{association_name} association." + raise BlueprinterError, "Class #{blueprint.name} does not inherit from " \ + 'Blueprinter::Base and is not a valid Blueprinter ' \ + "for #{association_name} association." end def jsonify(blob) diff --git a/lib/blueprinter/transformer.rb b/lib/blueprinter/transformer.rb index aefb24df..73d8d928 100644 --- a/lib/blueprinter/transformer.rb +++ b/lib/blueprinter/transformer.rb @@ -4,11 +4,11 @@ module Blueprinter # @api private class Transformer def transform(_result_hash, _primary_obj, _options = {}) - fail NotImplementedError, "A Transformer must implement #transform" + raise NotImplementedError, 'A Transformer must implement #transform' end def self.transform(result_hash, primary_obj, options = {}) - self.new.transform(result_hash, primary_obj, options) + new.transform(result_hash, primary_obj, options) end end end diff --git a/lib/blueprinter/version.rb b/lib/blueprinter/version.rb index cd3a79ea..7fceea31 100644 --- a/lib/blueprinter/version.rb +++ b/lib/blueprinter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Blueprinter - VERSION = '1.1.1' + VERSION = '1.1.2' end diff --git a/lib/blueprinter/view.rb b/lib/blueprinter/view.rb index bc550bbd..4db27600 100644 --- a/lib/blueprinter/view.rb +++ b/lib/blueprinter/view.rb @@ -20,14 +20,14 @@ def transformers view_transformers.empty? ? Blueprinter.configuration.default_transformers : view_transformers end - def track_definition_order(method, is_view = true) - if @sort_by_definition - @definition_order << DefinitionPlaceholder.new(method, is_view) - end + def track_definition_order(method, viewable: true) + return unless @sort_by_definition + + @definition_order << DefinitionPlaceholder.new(method, viewable) end def inherit(view) - view.fields.values.each do |field| + view.fields.each_value do |field| self << field end @@ -71,7 +71,7 @@ def add_transformer(custom_transformer) end def <<(field) - track_definition_order(field.name,false) + track_definition_order(field.name, viewable: false) fields[field.name] = field end end diff --git a/lib/blueprinter/view_collection.rb b/lib/blueprinter/view_collection.rb index 4248e2f4..0f4f9103 100644 --- a/lib/blueprinter/view_collection.rb +++ b/lib/blueprinter/view_collection.rb @@ -4,6 +4,7 @@ module Blueprinter # @api private class ViewCollection attr_reader :views, :sort_by_definition + def initialize @views = { identifier: View.new(:identifier), @@ -18,8 +19,8 @@ def inherit(view_collection) end end - def has_view?(view_name) - views.has_key? view_name + def view?(view_name) + views.key? view_name end def fields_for(view_name) @@ -28,8 +29,8 @@ def fields_for(view_name) fields, excluded_fields = sortable_fields(view_name) sorted_fields = sort_by_definition ? sort_by_def(view_name, fields) : fields.values.sort_by(&:name) - (identifier_fields + sorted_fields).tap do |fields| - fields.reject! { |field| excluded_fields.include?(field.name) } + (identifier_fields + sorted_fields).tap do |fields_array| + fields_array.reject! { |field| excluded_fields.include?(field.name) } end end @@ -69,7 +70,9 @@ def sortable_fields(view_name) # select and order members of fields according to traversal of the definition_orders def sort_by_def(view_name, fields) ordered_fields = {} - views[:default].definition_order.each { |definition| add_to_ordered_fields(ordered_fields, definition, fields, view_name) } + views[:default].definition_order.each do |definition| + add_to_ordered_fields(ordered_fields, definition, fields, view_name) + end ordered_fields.values end @@ -78,7 +81,9 @@ def sort_by_def(view_name, fields) def add_to_ordered_fields(ordered_fields, definition, fields, view_name_filter = nil) if definition.view? if view_name_filter.nil? || view_name_filter == definition.name - views[definition.name].definition_order.each { |_definition| add_to_ordered_fields(ordered_fields, _definition, fields) } + views[definition.name].definition_order.each do |defined| + add_to_ordered_fields(ordered_fields, defined, fields) + end end else ordered_fields[definition.name] = fields[definition.name] diff --git a/lib/generators/blueprinter/blueprint_generator.rb b/lib/generators/blueprinter/blueprint_generator.rb index 8486cf26..8ffc5bb6 100644 --- a/lib/generators/blueprinter/blueprint_generator.rb +++ b/lib/generators/blueprinter/blueprint_generator.rb @@ -3,39 +3,31 @@ module Blueprinter module Generators class BlueprintGenerator < ::Rails::Generators::NamedBase - desc "Generates blueprint for ActiveRecord model with the given NAME." + desc 'Generates blueprint for ActiveRecord model with the given NAME.' attr_accessor :options - source_root File.expand_path("../templates", __FILE__) + source_root File.expand_path('templates', __dir__) + class_option :blueprints_dir, default: 'app/blueprints', desc: 'path to new blueprint', aliases: '-d' + class_option :identifier, default: nil, + desc: 'Add an identifer to the generated blueprint, either uses :id or your specified value', aliases: '-i', banner: 'id' - class_option :blueprints_dir, default: "app/blueprints", desc: "path to new blueprint", aliases: "-d" + class_option :fields, type: :array, default: [], desc: 'Manually add specified fields' + class_option :detect_fields, type: :boolean, default: false, + desc: 'Introspect on the model to set fields in the generated blueprint. Will be merged with any manually specified' + class_option :associations, type: :array, default: [], desc: 'Manually add specified associations', aliases: '-a' - class_option :identifier, default: nil, desc: "Add an identifer to the generated blueprint, either uses :id or your specified value", aliases: "-i", banner: "id" - - - - class_option :fields, type: :array, default: [], desc: "Manually add specified fields" - - class_option :detect_fields, type: :boolean, default: false, desc: "Introspect on the model to set fields in the generated blueprint. Will be merged with any manually specified" - - - - class_option :associations, type: :array, default: [], desc: "Manually add specified associations", aliases: "-a" - - class_option :detect_associations, type: :boolean, default: false, desc: "Introspect on the model to set associations in the generated blueprint. Will be merged with any manually specified" - - - - class_option :wrap_at, type: :numeric, default: 80, desc: "Maximum length of generated fields line", aliases: "-w" - - class_option :indentation, type: :string, default: "two", desc: "Indentation of generated file", banner: "two|four|tab" + class_option :detect_associations, type: :boolean, default: false, + desc: 'Introspect on the model to set associations in the generated blueprint. Will be merged with any manually specified' + class_option :wrap_at, type: :numeric, default: 80, desc: 'Maximum length of generated fields line', aliases: '-w' + class_option :indentation, type: :string, default: 'two', desc: 'Indentation of generated file', + banner: 'two|four|tab' remove_class_option :skip_namespace @@ -44,30 +36,28 @@ def ensure_blueprint_dir end def create_blueprint - template "blueprint.rb", File.join(path, "#{file_path}_blueprint.rb") + template 'blueprint.rb', File.join(path, "#{file_path}_blueprint.rb") end - - private def path - options["blueprints_dir"] + options['blueprints_dir'] end def identifier_symbol - if options['identifier'] - options['identifier'] == "identifier" ? :id : options['identifier'] - end + return unless options['identifier'] + + options['identifier'] == 'identifier' ? :id : options['identifier'] end def fields - fs = if options["detect_fields"] - Array.new(options["fields"]).concat(introspected_fields) + fs = if options['detect_fields'] + Array.new(options['fields']).concat(introspected_fields) else - options["fields"] + options['fields'] end - fs.reject {|f| f.blank? }.uniq + fs.reject(&:blank?).uniq end def introspected_fields @@ -77,30 +67,29 @@ def introspected_fields # split at wrap_at chars, two indentations def formatted_fields two_indents = indent * 2 - fields_string = fields.reduce([]) do |memo, f| - if !memo.last.nil? + fields_string = fields.each_with_object([]) do |f, memo| + if memo.last.nil? + memo << " :#{f}," + else now = "#{memo.last} :#{f}," - if now.length > options["wrap_at"].to_i + if now.length > options['wrap_at'].to_i memo << ":#{f}," else memo[memo.length - 1] = now end - else - memo << " :#{f}," end - memo end.join("\n#{two_indents}") - fields_string[0,fields_string.length - 1] + fields_string[0, fields_string.length - 1] end def associations - as = if options["detect_associations"] - Array.new(options["associations"]).concat(introspected_associations.keys) + as = if options['detect_associations'] + Array.new(options['associations']).concat(introspected_associations.keys) else - options["associations"] + options['associations'] end - as.reject {|f| f.blank? }.uniq + as.reject(&:blank?).uniq end def introspected_associations @@ -114,15 +103,13 @@ def association_blueprint(association_name) def association_class(association_name) introspected_name = if introspected_associations[association_name].respond_to?(:klass) introspected_associations[association_name].klass.to_s - else - nil end "#{introspected_name || association_name.camelcase}Blueprint" end def indent - user_intended = {two: " ", four: " ", tab:"\t"}[options["indentation"].intern] - user_intended.nil? ? " " : user_intended + user_intended = { two: ' ', four: ' ', tab: "\t" }[options['indentation'].intern] + user_intended.nil? ? ' ' : user_intended end end end diff --git a/spec/integrations/base_spec.rb b/spec/integrations/base_spec.rb index e83a7961..c6db132a 100644 --- a/spec/integrations/base_spec.rb +++ b/spec/integrations/base_spec.rb @@ -492,7 +492,7 @@ def extract(association_name, object, _local_options, _options={}) end describe 'has_view?' do - subject { blueprint.has_view?(view) } + subject { blueprint.view?(view) } let(:blueprint) do Class.new(Blueprinter::Base) do From 80af61da3c8060eb9698080eb09cfbde6f3d4802 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Fri, 21 Apr 2023 01:22:53 +0530 Subject: [PATCH 12/23] update yard (#13) update yard and cleanup rubocop.yml workflow --- .github/workflows/rubocop.yml | 4 +--- Gemfile | 3 ++- Rakefile | 12 +++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 5be5b811..51276da8 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -16,6 +16,4 @@ jobs: ruby-version: '2.6.9' bundler-cache: true - name: Rubocop - # yard's rubocop.yml is interfering with the execution when using bundle exec - # without bundle exec github action isn't able to detect the executable - run: bundle exec rubocop --config ./.rubocop.yml + run: bundle exec rubocop diff --git a/Gemfile b/Gemfile index 95397caa..15a35db4 100644 --- a/Gemfile +++ b/Gemfile @@ -19,5 +19,6 @@ gem 'pry', '~> 0.14' gem 'rspec', '~> 3.12' gem 'rspec-rails', '~> 6.0' gem 'rubocop', '~> 1.44' +gem 'rubocop-rake' gem 'sqlite3', '~> 1.5' -gem 'yard', '~> 0.9' +gem 'yard', '>= 0.9.34' diff --git a/Rakefile b/Rakefile index de2306b4..363b14fe 100644 --- a/Rakefile +++ b/Rakefile @@ -4,6 +4,8 @@ require 'rdoc/task' require 'bundler/gem_tasks' require 'rake/testtask' require 'rspec/core/rake_task' +require 'yard' +require 'rubocop/rake_task' begin require 'bundler/setup' @@ -23,10 +25,18 @@ RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts = '--pattern spec/**/*_spec.rb --warnings' end +RuboCop::RakeTask.new + +YARD::Rake::YardocTask.new do |t| + t.files = Dir['lib/**/*'].reject do |file| + file.include?('lib/generators') + end +end + Rake::TestTask.new(:benchmarks) do |t| t.libs << 'spec' t.pattern = 'spec/benchmarks/**/*_test.rb' t.verbose = false end -task default: :spec +task default: %i[spec rubocop] From 1c37802fe28ed9b0cf4d642d3a258f3f6a3a8b7d Mon Sep 17 00:00:00 2001 From: Tianlu Date: Tue, 16 May 2023 17:44:43 +0800 Subject: [PATCH 13/23] Fixed gem install doc (#15) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 295dfa53..668e808c 100644 --- a/README.md +++ b/README.md @@ -954,7 +954,7 @@ $ bundle Or install it yourself as: ```bash -$ gem install blueprinter +$ gem install blueprinter-rb ``` You should also have `require 'json'` already in your project if you are not using Rails or if you are not using Oj. From bd3a7018691a3c54e31ae51e43f53ed5404abfde Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Wed, 24 May 2023 17:57:07 +0530 Subject: [PATCH 14/23] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 668e808c..38346d39 100644 --- a/README.md +++ b/README.md @@ -453,9 +453,9 @@ class UserBlueprint < Blueprinter::Base view :normal do # If first_name is an empty string, it will become "N/A" - field :first_name, default_if: Blueprinter::EmptyString, default: "N/A" + field :first_name, default_if: Blueprinter::EMPTY_STRING, default: "N/A" # If the projects association collection is empty, it will become nil - association :projects, blueprint: ProjectBlueprint, default_if: Blueprinter::EmptyCollection + association :projects, blueprint: ProjectBlueprint, default_if: Blueprinter::EMPTY_COLLECTION end end ``` From 6b8aa6521377b9e904196f697efac8f950fb23ed Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Tue, 13 Jun 2023 17:23:29 +0530 Subject: [PATCH 15/23] CI updates & fixes (#17) * fix rubocop * run only rspec from tests workflow --- .github/workflows/tests.yml | 2 +- Gemfile | 4 ++++ blueprinter.gemspec | 3 --- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7d6ef4f5..083fc71d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,4 +20,4 @@ jobs: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Run tests - run: bundle exec rake + run: bundle exec rake spec diff --git a/Gemfile b/Gemfile index 15a35db4..3e6dd5dc 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,10 @@ source 'https://rubygems.org' # development dependencies will be added by default to the :development group. gemspec +# officially supported gems for serialisation +gem 'oj', '~> 3.13' +gem 'yajl-ruby', '~> 1.4' + # Declare any dependencies that are still in development here instead of in # your gemspec. These might include edge Rails or gems from your path or # Git. Remember to move these dependencies to your gemspec before releasing diff --git a/blueprinter.gemspec b/blueprinter.gemspec index db69eb22..33be1bbd 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -22,8 +22,5 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.6.9' - s.add_development_dependency 'oj', '~> 3.13' - s.add_development_dependency 'yajl-ruby', '~> 1.4' - s.metadata['rubygems_mfa_required'] = 'true' end From b90d251d7098249b6760493a4c414db4ba920c43 Mon Sep 17 00:00:00 2001 From: Subramanya-Murugesan Date: Tue, 13 Jun 2023 17:31:54 +0530 Subject: [PATCH 16/23] Removed deprecations on `Blueprinter::Field` callables and `EmptyTypes` (#16) * Removed deprecations on Blueprinter::Field callables * Removed conditional procs with two arguments and modified version and changelog --- CHANGELOG.md | 3 ++ lib/blueprinter/empty_types.rb | 5 --- lib/blueprinter/field.rb | 11 ------- lib/blueprinter/version.rb | 2 +- .../shared/base_render_examples.rb | 31 ++++--------------- 5 files changed, 10 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 729576f8..98f1f10d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.2.0 - 2023/06/13 +* 💅 [ENHANCEMENT] if/:unless procs with two arguments and invalid empty type deprecations are now removed + ## 1.1.2 - 2023/02/06 * 💅 [ENHANCEMENT] Introduce rubocop and add a Github action for it diff --git a/lib/blueprinter/empty_types.rb b/lib/blueprinter/empty_types.rb index 5a5b24ce..03debe98 100644 --- a/lib/blueprinter/empty_types.rb +++ b/lib/blueprinter/empty_types.rb @@ -22,11 +22,6 @@ def use_default_value?(value, empty_type) value.is_a?(Hash) && value.empty? when Blueprinter::EMPTY_STRING value.to_s == '' - else - Blueprinter::Deprecation.report( - "Invalid empty type '#{empty_type}' received. Blueprinter will raise an error in the next major version." \ - 'Must be one of [nil, Blueprinter::EMPTY_COLLECTION, Blueprinter::EMPTY_HASH, Blueprinter::EMPTY_STRING]' - ) end end end diff --git a/lib/blueprinter/field.rb b/lib/blueprinter/field.rb index 2b783cf5..8783aab5 100644 --- a/lib/blueprinter/field.rb +++ b/lib/blueprinter/field.rb @@ -38,17 +38,6 @@ def unless_callable end def callable_from(condition) - callable = old_callable_from(condition) - - if callable && callable.arity == 2 - Blueprinter::Deprecation.report("`:#{condition}` conditions now expects 3 arguments instead of 2.") - ->(_field_name, obj, options) { callable.call(obj, options) } - else - callable - end - end - - def old_callable_from(condition) config = Blueprinter.configuration # Use field-level callable, or when not defined, try global callable diff --git a/lib/blueprinter/version.rb b/lib/blueprinter/version.rb index 7fceea31..da8d3137 100644 --- a/lib/blueprinter/version.rb +++ b/lib/blueprinter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Blueprinter - VERSION = '1.1.2' + VERSION = '1.2.0' end diff --git a/spec/integrations/shared/base_render_examples.rb b/spec/integrations/shared/base_render_examples.rb index 547c71db..6113ffcc 100644 --- a/spec/integrations/shared/base_render_examples.rb +++ b/spec/integrations/shared/base_render_examples.rb @@ -174,17 +174,18 @@ def extract(field_name, object, _local_options, _options={}) end context 'Given default_if option is invalid' do + before do + obj[:first_name] = "" + end + + let(:result) { %({"first_name":"","id":#{obj_id}}) } let(:blueprint) do Class.new(Blueprinter::Base) do field :id field :first_name, default_if: "INVALID_EMPTY_TYPE", default: "Unknown" end end - it('reports a deprecation message') do - allow(Blueprinter::Deprecation).to receive(:report) - blueprint.render(obj) - expect(Blueprinter::Deprecation).to have_received(:report).with(match(/Invalid empty type '.*' received. Blueprinter will raise an error in the next major version./)) - end + it('does not use the default value') { should eq(result) } end context "Given blueprint has ::field with nil value" do @@ -256,26 +257,6 @@ def extract(field_name, object, _local_options, _options={}) end context 'Given blueprint has ::field with a conditional argument' do - context 'Given conditional proc has deprecated two argument signature' do - let(:if_proc) { ->(_obj, _local_opts) { true } } - let(:unless_proc) { ->(_obj, _local_opts) { true } } - - let(:blueprint) do - Class.new(Blueprinter::Base) do - field :id - field :first_name, if: ->(_obj, _local_opts) { true } - field :last_name, unless: ->(_obj, _local_opts) { true } - end - end - - it('reports a deprecation warning') do - allow(Blueprinter::Deprecation).to receive(:report) - blueprint.render(obj) - expect(Blueprinter::Deprecation).to have_received(:report).with("`:if` conditions now expects 3 arguments instead of 2.") - expect(Blueprinter::Deprecation).to have_received(:report).with("`:unless` conditions now expects 3 arguments instead of 2.") - end - end - context 'Given conditional proc has three argument signature' do variants = %i[proc method].product([true, false]) From 8088594476b3ec0ff3f05cf4035ef3a7d79480d2 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Sat, 16 Sep 2023 01:43:14 +0530 Subject: [PATCH 17/23] update version --- CHANGELOG.md | 2 +- lib/blueprinter/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a295191c..f4208442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.30 - 2023/09/16 +## 0.30.0 - 2023/09/16 * 🚀 [FEATURE] Allow configuring custom array-like classes to be treated as collections when serializing. More details can be found [here](https://github.com/blueprinter-ruby/blueprinter/pull/6). Thanks to [@toddnestor](https://github.com/toddnestor). * 💅 [ENHANCEMENT] Reduce object allocations in fields calculations to save some memory. More details can be found [here](https://github.com/blueprinter-ruby/blueprinter/pull/5). Thanks to [@nametoolong](https://github.com/nametoolong). * 💅 [ENHANCEMENT] Introduce rubocop diff --git a/lib/blueprinter/version.rb b/lib/blueprinter/version.rb index a3b053a4..5470c163 100644 --- a/lib/blueprinter/version.rb +++ b/lib/blueprinter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Blueprinter - VERSION = '0.26.0'.freeze + VERSION = '0.30.0'.freeze end From 541af71323e6a05d981a166c39e4a1f482dac21d Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Sat, 16 Sep 2023 01:47:54 +0530 Subject: [PATCH 18/23] rubocop fixes --- .github/workflows/rubocop.yml | 19 ------------------- .github/workflows/tests.yml | 23 ----------------------- .rubocop.yml | 2 +- blueprinter.gemspec | 8 ++++++-- lib/blueprinter/version.rb | 2 +- 5 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 .github/workflows/rubocop.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml deleted file mode 100644 index 51276da8..00000000 --- a/.github/workflows/rubocop.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: "rubocop" -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Install Ruby and gems - uses: ruby/setup-ruby@v1 - with: - ruby-version: '2.6.9' - bundler-cache: true - - name: Rubocop - run: bundle exec rubocop diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 083fc71d..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: rspec -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] -permissions: - contents: read -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - ruby-version: [2.6.9, 2.7, 3.0, 3.1, 3.2] - steps: - - uses: actions/checkout@v3 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true - - name: Run tests - run: bundle exec rake spec diff --git a/.rubocop.yml b/.rubocop.yml index e3160f82..2c47452a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.6.9 + TargetRubyVersion: 2.7 NewCops: enable Exclude: - 'lib/generators/**/*' diff --git a/blueprinter.gemspec b/blueprinter.gemspec index defd926c..01cc3f26 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -$:.push File.expand_path('lib', __dir__) +$LOAD_PATH.push File.expand_path('lib', __dir__) # Maintain your gem's version: require 'blueprinter/version' @@ -13,10 +13,14 @@ Gem::Specification.new do |s| s.email = ['blueprinter@googlegroups.com'] s.homepage = 'https://github.com/procore-oss/blueprinter' s.summary = 'Simple Fast Declarative Serialization Library' - s.description = 'Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant.' + s.description = 'Blueprinter is a JSON Object Presenter for Ruby that takes business objects ' \ + 'and breaks them down into simple hashes and serializes them to JSON. ' \ + 'It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). ' \ + 'It is designed to be simple, direct, and performant.' s.license = 'MIT' s.files = Dir['{app,config,db,lib}/**/*', 'CHANGELOG.md', 'MIT-LICENSE', 'Rakefile', 'README.md'] s.required_ruby_version = '>= 2.7' + s.metadata['rubygems_mfa_required'] = 'true' end diff --git a/lib/blueprinter/version.rb b/lib/blueprinter/version.rb index 5470c163..2e640cbc 100644 --- a/lib/blueprinter/version.rb +++ b/lib/blueprinter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Blueprinter - VERSION = '0.30.0'.freeze + VERSION = '0.30.0' end From 87033b8bfbd84bc7c06dba45a687a2be5a08950f Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Sat, 16 Sep 2023 01:49:57 +0530 Subject: [PATCH 19/23] changes URLs to procore-oss/blueprinter in changelog --- CHANGELOG.md | 104 +++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4208442..14ff8a5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,40 +1,40 @@ ## 0.30.0 - 2023/09/16 -* 🚀 [FEATURE] Allow configuring custom array-like classes to be treated as collections when serializing. More details can be found [here](https://github.com/blueprinter-ruby/blueprinter/pull/6). Thanks to [@toddnestor](https://github.com/toddnestor). -* 💅 [ENHANCEMENT] Reduce object allocations in fields calculations to save some memory. More details can be found [here](https://github.com/blueprinter-ruby/blueprinter/pull/5). Thanks to [@nametoolong](https://github.com/nametoolong). +* 🚀 [FEATURE] Allow configuring custom array-like classes to be treated as collections when serializing. More details can be found [here](https://github.com/procore-oss/blueprinter/pull/327). Thanks to [@toddnestor](https://github.com/toddnestor). +* 💅 [ENHANCEMENT] Reduce object allocations in fields calculations to save some memory. More details can be found [here](https://github.com/procore-oss/blueprinter/pull/327). Thanks to [@nametoolong](https://github.com/nametoolong). * 💅 [ENHANCEMENT] Introduce rubocop * 💅 [ENHANCEMENT] if/:unless procs with two arguments and invalid empty type deprecations are now removed ## 0.26.0 - 2023/08/17 * 🐛 [BREAKING] Transition to GitHub Actions from CircleCI and update to handle Ruby versions 2.7, 3.0, 3.1, 3.2. Drop support for any ruby version less than 2.7. See [#307](https://github.com/procore-oss/blueprinter/pull/307) ## 0.25.3 - 2021/03/03 -* 🐛 [BUGFIX] Fixes issue where fields and associations that are redefined by later views were not properly overwritten. See [#201](https://github.com/procore/blueprinter/pull/201) thanks to [@Berardpi](https://github.com/Berardpi). +* 🐛 [BUGFIX] Fixes issue where fields and associations that are redefined by later views were not properly overwritten. See [#201](https://github.com/procore-oss/blueprinter/pull/201) thanks to [@Berardpi](https://github.com/Berardpi). ## 0.25.2 - 2020/11/19 -* 🚀 [FEATURE] Make deprecation behavior configurable (`:silence`, `:stderror`, `:raise`). See [#248](https://github.com/procore/blueprinter/pull/248) thanks to [@mcclayton](https://github.com/mcclayton). +* 🚀 [FEATURE] Make deprecation behavior configurable (`:silence`, `:stderror`, `:raise`). See [#248](https://github.com/procore-oss/blueprinter/pull/248) thanks to [@mcclayton](https://github.com/mcclayton). ## 0.25.1 - 2020/08/18 -* 🐛 [BUGFIX] Raise Blueprinter::BlueprinterError if Blueprint given is not of class Blueprinter::Base. Before it just raised a generic `undefined method 'prepare'`. See [#233](https://github.com/procore/blueprinter/pull/233) thanks to [@caws](https://github.com/caws). +* 🐛 [BUGFIX] Raise Blueprinter::BlueprinterError if Blueprint given is not of class Blueprinter::Base. Before it just raised a generic `undefined method 'prepare'`. See [#233](https://github.com/procore-oss/blueprinter/pull/233) thanks to [@caws](https://github.com/caws). ## 0.25.0 - 2020/07/06 -* 🚀 [FEATURE] Enable default `Blueprinter::Transformer`s to be set in the global configuration. [#222](https://github.com/procore/blueprinter/pull/222). Thanks to [@supremebeing7](https://github.com/supremebeing7). +* 🚀 [FEATURE] Enable default `Blueprinter::Transformer`s to be set in the global configuration. [#222](https://github.com/procore-oss/blueprinter/pull/222). Thanks to [@supremebeing7](https://github.com/supremebeing7). ## 0.24.0 - 2020/06/22 -* 🚀 [FEATURE] Add an `options` option to associations to facilitate passing options from one blueprint to another. [#220](https://github.com/procore/blueprinter/pull/220). Thanks to [@mcclayton](https://github.com/mcclayton). +* 🚀 [FEATURE] Add an `options` option to associations to facilitate passing options from one blueprint to another. [#220](https://github.com/procore-oss/blueprinter/pull/220). Thanks to [@mcclayton](https://github.com/mcclayton). ## 0.23.4 - 2020/04/28 -* 🚀 [FEATURE] Public class method `has_view?` on Blueprinter::Base subclasses introduced in [#213](https://github.com/procore/blueprinter/pull/213). Thanks to [@spencerneste](https://github.com/spencerneste). +* 🚀 [FEATURE] Public class method `has_view?` on Blueprinter::Base subclasses introduced in [#213](https://github.com/procore-oss/blueprinter/pull/213). Thanks to [@spencerneste](https://github.com/spencerneste). ## 0.23.3 - 2020/04/07 -* 🐛 [BUGFIX] Fixes issue where `exclude` fields in deeply nested views were not respected. Resolved issue [207](https://github.com/procore/blueprinter/issues/207) in [#208](https://github.com/procore/blueprinter/pull/208) by [@tpltn](https://github.com/tpltn). +* 🐛 [BUGFIX] Fixes issue where `exclude` fields in deeply nested views were not respected. Resolved issue [207](https://github.com/procore-oss/blueprinter/issues/207) in [#208](https://github.com/procore-oss/blueprinter/pull/208) by [@tpltn](https://github.com/tpltn). ## 0.23.2 - 2020/03/16 -* 🐛 [BUGFIX] Fixes issue where fields "bled" into other views due to merge side-effects. Resolved issue [205](https://github.com/procore/blueprinter/issues/205) in [#204](https://github.com/procore/blueprinter/pull/204) by [@trevorrjohn](https://github.com/trevorrjohn). +* 🐛 [BUGFIX] Fixes issue where fields "bled" into other views due to merge side-effects. Resolved issue [205](https://github.com/procore-oss/blueprinter/issues/205) in [#204](https://github.com/procore-oss/blueprinter/pull/204) by [@trevorrjohn](https://github.com/trevorrjohn). ## 0.23.1 - 2020/03/13 -* 🐛 [BUGFIX] Fixes #172 where views would unintentionally ignore `sort_fields_by: :definition` configuration. Resolved in [#197](https://github.com/procore/blueprinter/pull/197) by [@wlkrw](https://github.com/wlkrw). +* 🐛 [BUGFIX] Fixes #172 where views would unintentionally ignore `sort_fields_by: :definition` configuration. Resolved in [#197](https://github.com/procore-oss/blueprinter/pull/197) by [@wlkrw](https://github.com/wlkrw). ## 0.23.0 - 2020/01/31 -* 🚀 [FEATURE] Configurable default extractor introduced in [#198](https://github.com/procore/blueprinter/pull/198) by [@wlkrw](https://github.com/wlkrw). You can now set a default extractor like so: +* 🚀 [FEATURE] Configurable default extractor introduced in [#198](https://github.com/procore-oss/blueprinter/pull/198) by [@wlkrw](https://github.com/wlkrw). You can now set a default extractor like so: ``` Blueprinter.configure do |config| config.extractor_default = MyAutoExtractor @@ -42,22 +42,22 @@ end ``` ## 0.22.0 - 2019/12/26 -* 🚀 [FEATURE] Add rails generators. See `rails g blueprinter:blueprint --help` for usage. Introduced in [#176](https://github.com/procore/blueprinter/pull/176) by [@wlkrw](https://github.com/wlkrw). +* 🚀 [FEATURE] Add rails generators. See `rails g blueprinter:blueprint --help` for usage. Introduced in [#176](https://github.com/procore-oss/blueprinter/pull/176) by [@wlkrw](https://github.com/wlkrw). ## 0.21.0 - 2019/12/19 -* 🚀 [FEATURE] Ability to specify `default_if` field/association option for more control on when the default value is applied. [191](https://github.com/procore/blueprinter/pull/191). Thanks to [@mcclayton](https://github.com/mcclayton). +* 🚀 [FEATURE] Ability to specify `default_if` field/association option for more control on when the default value is applied. [191](https://github.com/procore-oss/blueprinter/pull/191). Thanks to [@mcclayton](https://github.com/mcclayton). ## 0.20.0 - 2019/10/15 -* 🚀 [FEATURE] Ability to include multiple views in a single method call with `include_views`. [184](https://github.com/procore/blueprinter/pull/184). Thanks to [@narendranvelmurugan](https://github.com/narendranvelmurugan). +* 🚀 [FEATURE] Ability to include multiple views in a single method call with `include_views`. [184](https://github.com/procore-oss/blueprinter/pull/184). Thanks to [@narendranvelmurugan](https://github.com/narendranvelmurugan). -* 💅 [ENHANCEMENT] Update field-level conditional settings to reflect new three-argument syntax. [183](https://github.com/procore/blueprinter/pull/183). Thanks to [@danirod](https://github.com/danirod). +* 💅 [ENHANCEMENT] Update field-level conditional settings to reflect new three-argument syntax. [183](https://github.com/procore-oss/blueprinter/pull/183). Thanks to [@danirod](https://github.com/danirod). -* 💅 [ENHANCEMENT] Modify Extractor access control in documentation. [182](https://github.com/procore/blueprinter/pull/182). Thanks to [@cagmz](https://github.com/cagmz). +* 💅 [ENHANCEMENT] Modify Extractor access control in documentation. [182](https://github.com/procore-oss/blueprinter/pull/182). Thanks to [@cagmz](https://github.com/cagmz). -* 💅 [ENHANCEMENT] Fix the Transformer example documentation. [174](https://github.com/procore/blueprinter/pull/174). Thanks to [@tjwallace](https://github.com/tjwallace). +* 💅 [ENHANCEMENT] Fix the Transformer example documentation. [174](https://github.com/procore-oss/blueprinter/pull/174). Thanks to [@tjwallace](https://github.com/tjwallace). ## 0.19.0 - 2019/07/24 -* 🚀 [FEATURE] Added ability to specify transformers for Blueprinter views to further process the resulting hash before serialization. [#164](https://github.com/procore/blueprinter/pull/164). Thanks to [@amalarayfreshworks](https://github.com/amalarayfreshworks). +* 🚀 [FEATURE] Added ability to specify transformers for Blueprinter views to further process the resulting hash before serialization. [#164](https://github.com/procore-oss/blueprinter/pull/164). Thanks to [@amalarayfreshworks](https://github.com/amalarayfreshworks). ## 0.18.0 - 2019/05/29 @@ -65,83 +65,83 @@ end In order to be compliant with the the next major release, all conditional :if/:unless procs must be augmented to take in three arguments instead of two. i.e. `(obj, options)` to `(field_name, obj, options)`. ## 0.17.0 - 2019/05/23 -* 🐛 [BUGFIX] Fixing view: :identifier including non-identifier fields. [#154](https://github.com/procore/blueprinter/pull/154). Thanks to [@AllPurposeName](https://github.com/AllPurposeName). +* 🐛 [BUGFIX] Fixing view: :identifier including non-identifier fields. [#154](https://github.com/procore-oss/blueprinter/pull/154). Thanks to [@AllPurposeName](https://github.com/AllPurposeName). -* 💅 [ENHANCEMENT] Add ability to override :extractor option for an ::association. [#152](https://github.com/procore/blueprinter/pull/152). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). +* 💅 [ENHANCEMENT] Add ability to override :extractor option for an ::association. [#152](https://github.com/procore-oss/blueprinter/pull/152). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). ## 0.16.0 - 2019/04/03 -* 🚀 [FEATURE] Add ability to exclude multiple fields inline using `excludes`. [#141](https://github.com/procore/blueprinter/pull/141). Thanks to [@pabhinaya](https://github.com/pabhinaya). +* 🚀 [FEATURE] Add ability to exclude multiple fields inline using `excludes`. [#141](https://github.com/procore-oss/blueprinter/pull/141). Thanks to [@pabhinaya](https://github.com/pabhinaya). ## 0.15.0 - 2019/04/01 -* 🚀 [FEATURE] Add ability to pass in `datetime_format` field option as either a string representing the strftime format, or a Proc which takes in the Date or DateTime object and returns the formatted date. [#145](https://github.com/procore/blueprinter/pull/145). Thanks to [@mcclayton](https://github.com/mcclayton). +* 🚀 [FEATURE] Add ability to pass in `datetime_format` field option as either a string representing the strftime format, or a Proc which takes in the Date or DateTime object and returns the formatted date. [#145](https://github.com/procore-oss/blueprinter/pull/145). Thanks to [@mcclayton](https://github.com/mcclayton). ## 0.14.0 - 2019/04/01 -* 🚀 [FEATURE] Added a global `datetime_format` option. [#135](https://github.com/procore/blueprinter/pull/143). Thanks to [@ritikesh](https://github.com/ritikesh). +* 🚀 [FEATURE] Added a global `datetime_format` option. [#135](https://github.com/procore-oss/blueprinter/pull/143). Thanks to [@ritikesh](https://github.com/ritikesh). ## 0.13.2 - 2019/03/14 -* 🐛 [BUGFIX] Replacing use of rails-specific method `Hash::except` so that Blueprinter continues to work in non-Rails environments. [#140](https://github.com/procore/blueprinter/pull/140). Thanks to [@checkbutton](https://github.com/checkbutton). +* 🐛 [BUGFIX] Replacing use of rails-specific method `Hash::except` so that Blueprinter continues to work in non-Rails environments. [#140](https://github.com/procore-oss/blueprinter/pull/140). Thanks to [@checkbutton](https://github.com/checkbutton). ## 0.13.1 - 2019/03/02 -* 💅 [MAINTENANCE | ENHANCEMENT] Cleaning up the `include_associations` section. This is not a documented/supported feature and is calling `respond_to?(:klass)` on every object passed to blueprinter. [#139](https://github.com/procore/blueprinter/pull/139). Thanks to [@ritikesh](https://github.com/ritikesh). +* 💅 [MAINTENANCE | ENHANCEMENT] Cleaning up the `include_associations` section. This is not a documented/supported feature and is calling `respond_to?(:klass)` on every object passed to blueprinter. [#139](https://github.com/procore-oss/blueprinter/pull/139). Thanks to [@ritikesh](https://github.com/ritikesh). ## 0.13.0 - 2019/02/07 -* 🚀 [FEATURE] Added an option to render with a root key. [#135](https://github.com/procore/blueprinter/pull/135). Thanks to [@ritikesh](https://github.com/ritikesh). -* 🚀 [FEATURE] Added an option to render with a top-level meta attribute. [#135](https://github.com/procore/blueprinter/pull/135). Thanks to [@ritikesh](https://github.com/ritikesh). +* 🚀 [FEATURE] Added an option to render with a root key. [#135](https://github.com/procore-oss/blueprinter/pull/135). Thanks to [@ritikesh](https://github.com/ritikesh). +* 🚀 [FEATURE] Added an option to render with a top-level meta attribute. [#135](https://github.com/procore-oss/blueprinter/pull/135). Thanks to [@ritikesh](https://github.com/ritikesh). ## 0.12.1 - 2019/01/24 -* 🐛 [BUGFIX] Fix boolean `false` values getting serialized as `null`. Please see PR [#132](https://github.com/procore/blueprinter/pull/132). Thanks to [@samsongz](https://github.com/samsongz). +* 🐛 [BUGFIX] Fix boolean `false` values getting serialized as `null`. Please see PR [#132](https://github.com/procore-oss/blueprinter/pull/132). Thanks to [@samsongz](https://github.com/samsongz). ## 0.12.0 - 2019/01/16 -* 🚀 [FEATURE] Enables the setting of global `:field_default` and `:association_default` option value in the Blueprinter Configuration that will be used as default values for fields and associations that evaluate to nil. [#128](https://github.com/procore/blueprinter/pull/128). Thanks to [@mcclayton](https://github.com/mcclayton). +* 🚀 [FEATURE] Enables the setting of global `:field_default` and `:association_default` option value in the Blueprinter Configuration that will be used as default values for fields and associations that evaluate to nil. [#128](https://github.com/procore-oss/blueprinter/pull/128). Thanks to [@mcclayton](https://github.com/mcclayton). ## 0.11.0 - 2019/01/15 -* 🚀 [FEATURE] Enables the setting of a global `:if`/`:unless` proc in the Blueprinter Configuration that will be used to evaluate the conditional render of all fields. [#127](https://github.com/procore/blueprinter/pull/127). Thanks to [@mcclayton](https://github.com/mcclayton). +* 🚀 [FEATURE] Enables the setting of a global `:if`/`:unless` proc in the Blueprinter Configuration that will be used to evaluate the conditional render of all fields. [#127](https://github.com/procore-oss/blueprinter/pull/127). Thanks to [@mcclayton](https://github.com/mcclayton). ## 0.10.0 - 2018/12/20 -* 🚀 [FEATURE] Association Blueprints can be dynamically evaluated using a proc. [#122](https://github.com/procore/blueprinter/pull/122). Thanks to [@ritikesh](https://github.com/ritikesh). +* 🚀 [FEATURE] Association Blueprints can be dynamically evaluated using a proc. [#122](https://github.com/procore-oss/blueprinter/pull/122). Thanks to [@ritikesh](https://github.com/ritikesh). ## 0.9.0 - 2018/11/29 -* 🚀 [FEATURE] Added a `render_as_json` API. Similar to `render_as_hash` but returns a JSONified hash. Please see pr [#119](https://github.com/procore/blueprinter/pull/119). Thanks to [@ritikesh](https://github.com/ritikesh). -* 🚀 [FEATURE] Sorting of fields in the response is now configurable to sort by definition or by name(asc only). Please see pr [#119](https://github.com/procore/blueprinter/pull/119). Thanks to [@ritikesh](https://github.com/ritikesh). -* 💅 [ENHANCEMENT] Updated readme for above features and some existing undocumented features like `exclude fields`, `render_as_hash`. Please see pr [#119](https://github.com/procore/blueprinter/pull/119). Thanks to [@ritikesh](https://github.com/ritikesh). +* 🚀 [FEATURE] Added a `render_as_json` API. Similar to `render_as_hash` but returns a JSONified hash. Please see pr [#119](https://github.com/procore-oss/blueprinter/pull/119). Thanks to [@ritikesh](https://github.com/ritikesh). +* 🚀 [FEATURE] Sorting of fields in the response is now configurable to sort by definition or by name(asc only). Please see pr [#119](https://github.com/procore-oss/blueprinter/pull/119). Thanks to [@ritikesh](https://github.com/ritikesh). +* 💅 [ENHANCEMENT] Updated readme for above features and some existing undocumented features like `exclude fields`, `render_as_hash`. Please see pr [#119](https://github.com/procore-oss/blueprinter/pull/119). Thanks to [@ritikesh](https://github.com/ritikesh). ## 0.8.0 - 2018/11/19 -* 🚀 [FEATURE] Extend Support for other JSON encoders like yajl-ruby. Please see pr [#118](https://github.com/procore/blueprinter/pull/118). Thanks to [@ritikesh](https://github.com/ritikesh). -* 🐛 [BUGFIX] Do not raise error on null date with `date_format` option. Please see pr [#117](https://github.com/procore/blueprinter/pull/117). Thanks to [@tpltn](https://github.com/tpltn). -* 🚀 [FEATURE] Add `default` option to `field`s which will be used as the serialized value instead of `null` when the field evaluates to null. Please see pr [#115](https://github.com/procore/blueprinter/pull/115). Thanks to [@mcclayton](https://github.com/mcclayton). -* 🐛 [BUGFIX] Made Base.associations completely private since they are not used outside of the Blueprinter base. Please see pr [#112](https://github.com/procore/blueprinter/pull/112). Thanks to [@philipqnguyen](https://github.com/philipqnguyen). -* 🐛 [BUGFIX] Fix issue where entire Blueprinter module was marked api private. Please see pr [#111](https://github.com/procore/blueprinter/pull/111). Thanks to [@philipqnguyen](https://github.com/philipqnguyen). -* 🚀 [FEATURE] Allow identifiers to be defined with a block. Please see pr [#110](https://github.com/procore/blueprinter/pull/110). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). -* 💅 [ENHANCEMENT] Update docs regarding the args yielded to blocks. Please see pr [#108](https://github.com/procore/blueprinter/pull/108). Thanks to [@philipqnguyen](https://github.com/philipqnguyen). -* 💅 [ENHANCEMENT] Use `field` method in fields. Please see pr [#107](https://github.com/procore/blueprinter/pull/107). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). +* 🚀 [FEATURE] Extend Support for other JSON encoders like yajl-ruby. Please see pr [#118](https://github.com/procore-oss/blueprinter/pull/118). Thanks to [@ritikesh](https://github.com/ritikesh). +* 🐛 [BUGFIX] Do not raise error on null date with `date_format` option. Please see pr [#117](https://github.com/procore-oss/blueprinter/pull/117). Thanks to [@tpltn](https://github.com/tpltn). +* 🚀 [FEATURE] Add `default` option to `field`s which will be used as the serialized value instead of `null` when the field evaluates to null. Please see pr [#115](https://github.com/procore-oss/blueprinter/pull/115). Thanks to [@mcclayton](https://github.com/mcclayton). +* 🐛 [BUGFIX] Made Base.associations completely private since they are not used outside of the Blueprinter base. Please see pr [#112](https://github.com/procore-oss/blueprinter/pull/112). Thanks to [@philipqnguyen](https://github.com/philipqnguyen). +* 🐛 [BUGFIX] Fix issue where entire Blueprinter module was marked api private. Please see pr [#111](https://github.com/procore-oss/blueprinter/pull/111). Thanks to [@philipqnguyen](https://github.com/philipqnguyen). +* 🚀 [FEATURE] Allow identifiers to be defined with a block. Please see pr [#110](https://github.com/procore-oss/blueprinter/pull/110). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). +* 💅 [ENHANCEMENT] Update docs regarding the args yielded to blocks. Please see pr [#108](https://github.com/procore-oss/blueprinter/pull/108). Thanks to [@philipqnguyen](https://github.com/philipqnguyen). +* 💅 [ENHANCEMENT] Use `field` method in fields. Please see pr [#107](https://github.com/procore-oss/blueprinter/pull/107). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). ## 0.7.0 - 2018/10/17 -* [FEATURE] Allow associations to be defined with a block. Please see pr [#106](https://github.com/procore/blueprinter/pull/106). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). -* [FEATURE] Inherit view definition when using inheritance. Please see pr [#105](https://github.com/procore/blueprinter/pull/105). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). +* [FEATURE] Allow associations to be defined with a block. Please see pr [#106](https://github.com/procore-oss/blueprinter/pull/106). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). +* [FEATURE] Inherit view definition when using inheritance. Please see pr [#105](https://github.com/procore-oss/blueprinter/pull/105). Thanks to [@hugopeixoto](https://github.com/hugopeixoto). ## 0.6.0 - 2018/06/05 * 🚀 [FEATURE] Add `date_time` format as an option to `field`. Please see pr #68. Thanks to [@njbbaer](https://github.com/njbbaer). -* 🚀 [FEATURE] Add conditional field support `:unless` and `:if` as an option to `field`. Please see pr [#86](https://github.com/procore/blueprinter/pull/86). Thanks to [@ojab](https://github.com/ojab). -* 🐛 [BUGFIX] Fix case where miscellaneous options were not being passed through the `AutoExtractor`. See pr [#83](https://github.com/procore/blueprinter/pull/83). +* 🚀 [FEATURE] Add conditional field support `:unless` and `:if` as an option to `field`. Please see pr [#86](https://github.com/procore-oss/blueprinter/pull/86). Thanks to [@ojab](https://github.com/ojab). +* 🐛 [BUGFIX] Fix case where miscellaneous options were not being passed through the `AutoExtractor`. See pr [#83](https://github.com/procore-oss/blueprinter/pull/83). ## 0.5.0 - 2018/05/15 * 🚀 [FEATURE] Add `default` option to `association` which will be used as the serialized value instead of `null` when the association evaluates to null. -See PR [#78](https://github.com/procore/blueprinter/pull/78) by [@vinaya-procore](https://github.com/vinaya-procore). +See PR [#78](https://github.com/procore-oss/blueprinter/pull/78) by [@vinaya-procore](https://github.com/vinaya-procore). ## 0.4.0 - 2018/05/02 * 🚀 [FEATURE] Add `render_as_hash` which will output a hash instead of -a JSON String. See PR [#76](https://github.com/procore/blueprinter/pull/76) by [@amayer171](https://github.com/amayer171) and Issue [#73](https://github.com/procore/blueprinter/issues/73). +a JSON String. See PR [#76](https://github.com/procore-oss/blueprinter/pull/76) by [@amayer171](https://github.com/amayer171) and Issue [#73](https://github.com/procore-oss/blueprinter/issues/73). ## 0.3.0 - 2018/04/05 @@ -158,7 +158,7 @@ field(:first_name, extractor: CustomExtractor) ``` * 💅 [ENHANCEMENT] Renamed Serializer classes to Extractor. See #72. -* 💅 [ENHANCEMENT] Updated README. See pr [#66](https://github.com/procore/blueprinter/pull/66), [#65](https://github.com/procore/blueprinter/pull/65) +* 💅 [ENHANCEMENT] Updated README. See pr [#66](https://github.com/procore-oss/blueprinter/pull/66), [#65](https://github.com/procore-oss/blueprinter/pull/65) ## 0.2.0 - 2018/01/22 @@ -167,8 +167,8 @@ field(:first_name, extractor: CustomExtractor) association :comments, blueprint: CommentsBlueprint ``` -* 🐛 [BUGFIX] Remove Optimizer class. See [#61](https://github.com/procore/blueprinter/pull/61). -* 🐛 [BUGFIX] Require associated objects to have a Blueprint, so that objects will always serialize properly. See [#60](https://github.com/procore/blueprinter/pull/60). +* 🐛 [BUGFIX] Remove Optimizer class. See [#61](https://github.com/procore-oss/blueprinter/pull/61). +* 🐛 [BUGFIX] Require associated objects to have a Blueprint, so that objects will always serialize properly. See [#60](https://github.com/procore-oss/blueprinter/pull/60). ## 0.1.0 - 2018/01/17 From 0b6034ee8e1ca8fe30b55f18f042de1de83138b1 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Sat, 16 Sep 2023 01:51:13 +0530 Subject: [PATCH 20/23] update readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 97bbf34e..922464bf 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,6 @@ Blueprinter.configure do |config| end ``` ----
@@ -212,7 +211,6 @@ If either of the above two developer conveniences are not desired, you can simpl
Root ---- You can also optionally pass in a root key to wrap your resulting json in: From 74e1caea1e242be199b8efe612eefa2410489b20 Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Sat, 16 Sep 2023 01:52:33 +0530 Subject: [PATCH 21/23] logo --- blueprinter_logo.svg | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 blueprinter_logo.svg diff --git a/blueprinter_logo.svg b/blueprinter_logo.svg new file mode 100644 index 00000000..c5b65fd7 --- /dev/null +++ b/blueprinter_logo.svg @@ -0,0 +1,17 @@ + + + + Blueprinter_option3 + Created with Sketch. + + + + + + + + + + + + \ No newline at end of file From c3b7c3002f2e01fc6f34340d6995f56ed38ee6dd Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Sat, 16 Sep 2023 13:42:54 +0530 Subject: [PATCH 22/23] max LineLength to 125 --- .rubocop.yml | 2 +- lib/blueprinter/extractors/association_extractor.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2c47452a..ecc2c16d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,7 +14,7 @@ Style/SafeNavigation: Enabled: false Layout/LineLength: - Max: 175 + Max: 125 Lint/MissingSuper: Enabled: false diff --git a/lib/blueprinter/extractors/association_extractor.rb b/lib/blueprinter/extractors/association_extractor.rb index ba100c93..a87ba0eb 100644 --- a/lib/blueprinter/extractors/association_extractor.rb +++ b/lib/blueprinter/extractors/association_extractor.rb @@ -24,7 +24,9 @@ def extract(association_name, object, local_options, options = {}) private def default_value(association_options) - association_options.key?(:default) ? association_options.fetch(:default) : Blueprinter.configuration.association_default + return association_options.fetch(:default) if association_options.key?(:default) + + Blueprinter.configuration.association_default end def association_blueprint(blueprint, value) From 767420a9ee8b34d4d36db3c6ccdd20daa873a53f Mon Sep 17 00:00:00 2001 From: Ritikesh Date: Tue, 19 Sep 2023 15:12:12 +0530 Subject: [PATCH 23/23] Update README.md Co-authored-by: Jake Sheehy Signed-off-by: Ritikesh --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 922464bf..e208abde 100644 --- a/README.md +++ b/README.md @@ -984,7 +984,7 @@ Output: Add this line to your application's Gemfile: ```ruby -gem 'blueprinter-rb' +gem 'blueprinter' ``` And then execute: