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/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..827a3ce4 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ + + +Checklist: + +* [ ] I have updated the necessary documentation +* [ ] I have updated the changelog, if necessary (CHANGELOG.md) +* [ ] I have signed off all my commits as required by [DCO](../CONTRIBUTING.md#legal) +* [ ] My build is green diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 00000000..413909e8 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: / + schedule: + interval: "weekly" + timezone: "America/Los_Angeles" + labels: + - "dependabot" + - "docker" + - "dependencies" diff --git a/.github/workflows/auto-assign-author.yaml b/.github/workflows/auto-assign-author.yaml new file mode 100644 index 00000000..db221728 --- /dev/null +++ b/.github/workflows/auto-assign-author.yaml @@ -0,0 +1,13 @@ +name: 'Auto Author Assign' + +on: + pull_request_target: + types: [opened, reopened] + +jobs: + assign-author: + runs-on: ubuntu-latest + steps: + - uses: toshimaru/auto-author-assign@0fd2847dd52b3cb103d743049dcfb7f17d39c51f # (latest, untagged) + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..a9cc7b6d --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,24 @@ +name: Release +on: + workflow_run: + workflows: [Test] + types: [completed] + branches: [master, main] +jobs: + release: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@96f53100ba2a5449eb71d2e6604bbcd94b9449b5 # (latest, untagged) + - name: Version file changed + id: version-file-changed + uses: tj-actions/changed-files@ea41e772876ff19a8d86e3315c52ceff3dae1941 # (latest, untagged) + with: + files: lib/blueprinter/version.rb + - name: Release New Gem Version + if: ${{ steps.version-file-changed.outputs.any_changed == 'true' }} + uses: cadwallion/publish-rubygems-action@94a6f4cd5350581749c569b5001eecc864e3ad0b # (latest, untagged) + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + RUBYGEMS_API_KEY: ${{secrets.RUBY_GEMS_API_KEY}} + RELEASE_COMMAND: bundle exec rake release || true # Don't fail when deploy does not take place diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..e9df07bd --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,25 @@ +name: Test +on: + push: + branches: [master, main] + pull_request: + branches: [master, main] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby: ['2.7', '3.0', '3.1', '3.2'] + steps: + - uses: actions/checkout@96f53100ba2a5449eb71d2e6604bbcd94b9449b5 # (latest, untagged) + - name: Set up Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Installing dependencies + run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle + - name: Run tests + run: bundle exec rake + - name: Benchmarks + run: bundle exec rake benchmarks diff --git a/.gitignore b/.gitignore index e9d1c1a5..2dec6f8c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Gemfile.lock .vscode .DS_Store tmp/ +.tool-versions diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f051a68..1dc30489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.26.0 - 2023/00/00 +* 🐛 [FEATURE] Transition to GitHub Actions from CircleCI and update to handle Ruby versions 2.7, 3.0, 3.1, 3.2 + ## 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/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..f56f7f72 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,130 @@ +# Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Spam or other deceptive practices that take advantage of the community +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +. +All complaints will be reviewed and investigated promptly and fairly by +the [Procore Open Source Program Office (OSPO)](docs/contact.md) + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +. Translations are available at +. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..d5b8ff26 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,37 @@ +# Contributing to Procore Projects + +This document explains the common procedures expected by contributors while submitting code to Procore open source projects. + +## Code of Conduct + +Please read and abide by the [Code of Conduct](CODE_OF_CONDUCT.md) + +## General workflow + +Once a GitHub issue is accepted and assigned to you, please follow general workflow in order to submit your contribution: + +1. Fork the target repository under your GitHub username. +2. Create a branch in your forked repository for the changes you are about to make. +3. Commit your changes in the branch you created in step 2. All commits need to be signed-off. Check the [legal](#legal) section bellow for more details. +4. Push your commits to your remote fork. +5. Create a Pull Request from your remote fork pointing to the HEAD branch (usually `main` branch) of the target repository. +6. Check the GitHub build and ensure that all checks are green. + +## Legal + +Procore projects use Developer Certificate of Origin ([DCO](https://GitHub.com/apps/dco/)). + +Please sign-off your contributions by doing ONE of the following: + +* Use `git commit -s ...` with each commit to add the sign-off or +* Manually add a `Signed-off-by: Your Name ` to each commit message. + +The email address must match your primary GitHub email. You do NOT need cryptographic (e.g. gpg) signing. + +* Use `git commit -s --amend ...` to add a sign-off to the latest commit, if you forgot. + +*Note*: Some projects will provide specific configuration to ensure all commits are signed-off. Please check the project's documentation for more details. + +## Tests + +Make sure your changes are properly covered by automated tests. We aim to build an efficient test suite that is low cost to maintain and bring value to project. Prefer writing unit-tests over heavy end-to-end (e2e) tests. However, sometimes e2e tests are necessary. If you aren't sure, ask one of the maintainers about the requirements for your pull-request. diff --git a/EMERITUS.md b/EMERITUS.md new file mode 100644 index 00000000..71fd7bc3 --- /dev/null +++ b/EMERITUS.md @@ -0,0 +1,10 @@ +# Emeritus Approvers + +These are the people who have been approvers in the past, and have since retired from the role. + +We thank them for their service to the project. + +| Emeritus | GitHub ID | +| -------- | --------- | +| Adam Hess | [hparker](https://github.com/hparker) | +| Michael Clayton| [mcclayton](https://github.com/mcclayton) | diff --git a/README.md b/README.md index c257d894..7c17c24c 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,21 @@ -[![CircleCI](https://circleci.com/gh/procore/blueprinter.svg?style=svg)](https://circleci.com/gh/procore/blueprinter) +![Tests](https://github.com/procore/blueprinter/actions/workflows/test.yml/badge.svg?branch=master) [![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 + 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). ## Usage +
Basic @@ -31,6 +34,7 @@ end ``` and then, in your code: + ```ruby puts UserBlueprint.render(user) # Output is a JSON string ``` @@ -49,7 +53,6 @@ And the output would look like: ---
-
Collections @@ -83,7 +86,6 @@ This will result in JSON that looks something like this: ---
-
Renaming @@ -114,13 +116,13 @@ This will result in JSON that looks something like this: ---
-
Views --- You may define different outputs by utilizing views: + ```ruby class UserBlueprint < Blueprinter::Base identifier :uuid @@ -137,14 +139,17 @@ class UserBlueprint < Blueprinter::Base end end ``` + A view can include fields from another view by utilizing `include_view` and `include_views`. Usage: + ```ruby puts UserBlueprint.render(user, view: :extended) ``` Output: + ```json { "uuid": "733f0758-8f21-4719-875f-262c3ec743af", @@ -158,7 +163,6 @@ Output: ---
-
Identifiers @@ -167,6 +171,7 @@ Output: `identifier`s are used to specify a field or method name used as an identifier. Usually, this is something like `:id`. Example: + ```rb class UserBlueprint < Blueprinter::Base identifier :uuid @@ -184,13 +189,13 @@ 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 class UserBlueprint < Blueprinter::Base identifier :uuid @@ -203,11 +208,13 @@ end ``` Usage: + ```ruby puts UserBlueprint.render(user, view: :normal, root: :user) ``` Output: + ```json { "user": { @@ -222,13 +229,13 @@ Output: ---
-
Meta Attributes --- You can additionally add meta-data to the json as well: + ```ruby class UserBlueprint < Blueprinter::Base identifier :uuid @@ -241,6 +248,7 @@ end ``` Usage: + ```ruby json = UserBlueprint.render(user, view: :normal, root: :user, meta: {links: [ 'https://app.mydomain.com', @@ -250,6 +258,7 @@ puts json ``` Output: + ```json { "user": { @@ -266,18 +275,19 @@ Output: } } ``` + _NOTE:_ For meta attributes, a [root](#root) is mandatory. ---
-
Exclude Fields --- You can specifically choose to exclude certain fields for specific views + ```ruby class UserBlueprint < Blueprinter::Base identifier :uuid @@ -296,11 +306,13 @@ end ``` Usage: + ```ruby puts UserBlueprint.render(user, view: :extended) ``` Output: + ```json { "uuid": "733f0758-8f21-4719-875f-262c3ec743af", @@ -332,13 +344,13 @@ end ---
-
Associations --- You may include associated objects. Say for example, a user has projects: + ```ruby class ProjectBlueprint < Blueprinter::Base identifier :uuid @@ -357,11 +369,13 @@ end ``` Usage: + ```ruby puts UserBlueprint.render(user, view: :normal) ``` Output: + ```json { "uuid": "733f0758-8f21-4719-875f-262c3ec743af", @@ -383,6 +397,7 @@ Output: It is also possible to pass options from one Blueprint to another via an association. For example: + ```ruby class VehicleBlueprint < Blueprinter::Base identifier :uuid @@ -404,7 +419,6 @@ end ---
-
Default Association/Field Option @@ -412,7 +426,8 @@ end 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. -#### Global Config Setting +### Global Config Setting + ```ruby Blueprinter.configure do |config| config.field_default = "N/A" @@ -420,7 +435,8 @@ Blueprinter.configure do |config| end ``` -#### Field-level/Association-level Setting +### Field-level/Association-level Setting + ```ruby class UserBlueprint < Blueprinter::Base identifier :uuid @@ -435,7 +451,6 @@ end ---
-
default_if @@ -444,16 +459,20 @@ end 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). -#### Blueprinter::EMPTY_COLLECTION +### Blueprinter::EMPTY_COLLECTION + An empty array or empty active record collection. -#### Blueprinter::EMPTY_HASH +### Blueprinter::EMPTY_HASH + An empty hash. -#### Blueprinter::EMPTY_STRING +### Blueprinter::EMPTY_STRING + An empty string or symbol. -#### Field-level/Association-level Setting +#### Field-level/Association-level Setting - EMPTY_STRING + ```ruby class UserBlueprint < Blueprinter::Base identifier :uuid @@ -470,13 +489,13 @@ 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 class Task < ActiveRecord::Base belongs_to :taskable, polymorphic: true @@ -499,12 +518,12 @@ class TaskBlueprint < Blueprinter::Base end 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 @@ -539,7 +558,6 @@ Output: ---
-
Defining An Identifier Directly In The Blueprint @@ -572,7 +590,6 @@ Output: ---
-
Defining An Association Directly In The Blueprint @@ -617,7 +634,6 @@ Output: ---
-
Passing Additional Properties To #render @@ -652,7 +668,6 @@ Output: ---
-
Conditional Fields @@ -660,7 +675,8 @@ Output: Both the `field` and the global Blueprinter Configuration supports `:if` and `:unless` options that can be used to serialize fields conditionally. -#### Global Config Setting +### Global Config Setting - if and unless + ```ruby Blueprinter.configure do |config| config.if = ->(field_name, obj, _options) { !obj[field_name].nil? } @@ -669,6 +685,7 @@ end ``` #### Field-level Setting + ```ruby class UserBlueprint < Blueprinter::Base identifier :uuid @@ -682,7 +699,6 @@ _NOTE:_ The field-level setting overrides the global config setting (for the fie ---
-
Custom Formatting for Dates and Times @@ -693,18 +709,21 @@ This global or field-level option can be either a string representing the associ or a Proc which receives the original Date/DateTime object and returns the formatted value. When using a Proc, it is the Proc's responsibility to handle any errors in formatting. +#### Global Config Setting - datetime -#### Global Config Setting If a global datetime_format is set (either as a string format or a Proc), this option will be invoked and used to format all fields that respond to `strftime`. + ```ruby Blueprinter.configure do |config| config.datetime_format = ->(datetime) { datetime.nil? ? datetime : datetime.strftime("%s").to_i } end ``` -#### Field-level Setting +#### Field-level Setting - datetime_format + Usage (String Option): + ```ruby class UserBlueprint < Blueprinter::Base identifier :name @@ -713,6 +732,7 @@ end ``` Output: + ```json { "name": "John Doe", @@ -721,6 +741,7 @@ Output: ``` Usage (Proc Option): + ```ruby class UserBlueprint < Blueprinter::Base identifier :name @@ -729,6 +750,7 @@ end ``` Output: + ```json { "name": "John Doe", @@ -741,7 +763,6 @@ _NOTE:_ The field-level setting overrides the global config setting (for the fie ---
-
Transform Classes @@ -757,6 +778,7 @@ Whatever is returned from this `transform` method will end up being the resultin #### Example Create a Transform class extending from `Blueprinter::Transformer` + ```ruby class DynamicFieldTransformer < Blueprinter::Transformer def transform(hash, object, options) @@ -778,6 +800,7 @@ end ``` Then specify the transform to use for the view. + ```ruby class UserBlueprint < Blueprinter::Base fields :first_name, :last_name @@ -788,6 +811,7 @@ end #### Global Transforms You can also specify global default transformers. Create one or more transformer classes extending from `Blueprinter::Transformer` and set the `default_transformers` configuration + ```ruby class LowerCamelTransformer < Blueprinter::Transformer def transform(hash, _object, _options) @@ -817,6 +841,7 @@ Blueprinter gets a given objects' values from the fields definitions using extra #### Examples For a specific kind of field, create an extractor class extending from `Blueprinter::Extractor` + ```ruby class MyFieldExtractor < Blueprinter::Extractor def extract(_field_name, _object, _local_options, _options={}) @@ -833,6 +858,7 @@ end ``` For a global default, create an extractor class extending from `Blueprinter::AutoExtractor` and set the `extractor_default` configuration + ```ruby class MyAutoExtractor < Blueprinter::AutoExtractor def initialize @@ -883,6 +909,7 @@ end ``` Output: + ```json { "name": "John Doe", @@ -894,7 +921,6 @@ Output: ---
-
Deprecations @@ -911,7 +937,8 @@ However, deprecations can be configured to report at three different levels: | `:raise` | Deprecations will be raised as `Blueprinter::BlueprinterError`s | | `:silence` | Deprecations will be silenced and will not be raised or logged | -### Example: +### Example - deprecations + ```ruby Blueprinter.configure do |config| config.deprecations = :raise @@ -921,7 +948,6 @@ end ---
-
render_as_hash @@ -947,7 +973,6 @@ Output: ---
-
render_as_json @@ -973,8 +998,8 @@ Output: ---
- ## Installation + Add this line to your application's Gemfile: ```ruby @@ -982,13 +1007,15 @@ gem 'blueprinter' ``` And then execute: + ```bash -$ bundle +bundle ``` Or install it yourself as: + ```bash -$ gem install blueprinter +gem install blueprinter ``` You should also have `require 'json'` already in your project if you are not using Rails or if you are not using Oj. @@ -1028,12 +1055,15 @@ end _NOTE:_ You should be doing this only if you aren't using `yajl-ruby` through the JSON API by requiring `yajl/json_gem`. More details [here](https://github.com/brianmario/yajl-ruby#json-gem-compatibility-api). In this case, `JSON.generate` is patched to use `Yajl::Encoder.encode` internally. ## Contributing -Feel free to browse the issues, converse, and make pull requests. If you need help, first please see if there is already an issue for your problem. Otherwise, go ahead and make a new issue. + +Please read our [Contributing](CONTRIBUTING.md) file ### Tests + You can run tests with `bundle exec rake`. ### Maintain The Docs + We use Yard for documentation. Here are the following documentation rules: - Document all public methods we expect to be utilized by the end developers. @@ -1048,7 +1078,9 @@ documentation rules: - Methods that are not set to private due to ruby visibility rule limitations should be marked with `@api private`. ### Releasing a New Version + To release a new version, change the version number in `version.rb`, and update the `CHANGELOG.md`. Finally, maintainers need to run `bundle exec rake release`, which will automatically create a git tag for the version, push git commits and tags to Github, and push the `.gem` file to rubygems.org. ## License + The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). diff --git a/blueprinter.gemspec b/blueprinter.gemspec index 8cb9b026..798185d1 100644 --- a/blueprinter.gemspec +++ b/blueprinter.gemspec @@ -1,34 +1,33 @@ -$:.push File.expand_path("../lib", __FILE__) +$:.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" + s.name = 'blueprinter' s.version = Blueprinter::VERSION - s.authors = ["Adam Hess", "Derek Carter"] - s.email = ["adamhess1991@gmail.com"] - s.homepage = "https://github.com/procore/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 = ['Adam Hess', 'Derek Carter'] + s.email = ['blueprinter@googlegroups.com'] + s.homepage = 'https://github.com/procore/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['{app,config,db,lib}/**/*', 'CHANGELOG.md', 'MIT-LICENSE', 'Rakefile', 'README.md'] - s.required_ruby_version = '>= 2.2.2' + s.required_ruby_version = '>= 2.7' - 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 'activerecord', '~> 6.1.7' + s.add_development_dependency 'ammeter', '~> 1.1.4' + 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 'pry' + s.add_development_dependency 'rake' + s.add_development_dependency 'rspec', '~> 3.7' + s.add_development_dependency 'rspec-rails', '~> 6.0' + s.add_development_dependency 'sqlite3', '~> 1.4.2' + s.add_development_dependency 'yajl-ruby', '~> 1.4.1' + s.add_development_dependency 'yard', '~> 0.9.11' end diff --git a/spec/activerecord_helper.rb b/spec/activerecord_helper.rb index c3a45662..37f82e6c 100644 --- a/spec/activerecord_helper.rb +++ b/spec/activerecord_helper.rb @@ -1,9 +1,9 @@ require 'active_record' -require 'factories/model_factories.rb' +require 'factories/model_factories' ActiveRecord::Base.establish_connection( - adapter: "sqlite3", - database: ":memory:", + adapter: 'sqlite3', + database: ':memory:' ) class Vehicle < ActiveRecord::Base @@ -17,34 +17,35 @@ class Truck < ::Vehicle class User < ActiveRecord::Base attr_accessor :company, :description, :position, :active + has_many :vehicles def dynamic_fields - {"full_name" => "#{first_name} #{last_name}"} + { 'full_name' => "#{first_name} #{last_name}" } end end -ActiveRecord::Schema.define(version: 20181116094242) do - create_table "users", force: :cascade do |t| - t.string "first_name" - t.string "last_name" - t.string "email" - t.text "address" - t.datetime "birthday" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.datetime "deleted_at" - t.boolean "active" +ActiveRecord::Schema.define(version: 20_181_116_094_242) do + create_table :users, force: :cascade do |t| + t.string :first_name + t.string :last_name + t.string :email + t.text :address + t.datetime :birthday + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + t.datetime :deleted_at + t.boolean :active end - create_table "vehicles", force: :cascade do |t| - t.string "make" - t.string "model" - t.integer "miles" - t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["user_id"], name: "index_vehicles_on_user_id" + create_table :vehicles, force: :cascade do |t| + t.string :make + t.string :model + t.integer :miles + t.integer :user_id + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + t.index [:user_id], name: :index_vehicles_on_user_id end end