blueprinter_schema 0.4.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a5c36ae7940be0f29d7fa96352756ac959c03dfb61d968d4080d1368a7eb29c
4
- data.tar.gz: cf498e454ca5349f419ac3e2db8d1efe9ee686ae09d34570be8523757e983e42
3
+ metadata.gz: b10fc12e29b6f54a7f5515b3d97809bd65e1fded8acd99a2d9395339cf7b1b2c
4
+ data.tar.gz: 4f0403c88c922e8c026d4ac0b7dd686c1e88f7f0f3fcde3174f184bfb9e375b9
5
5
  SHA512:
6
- metadata.gz: d5eaf5134861ca54d30c5e1380ba7e0afa15db73c692bc84591903a04b2d3a2190628e8221fd58506c0c328cf2da149f4df7813faeec29b92d2333910487cc93
7
- data.tar.gz: 6259270843fd90b83c08d797d1cd81799072e5b5d0c4e2295353c9b963e6e06b8729dde7f45e41121d4416a709f11e8a1aa7ed0d2a977180de98424b4d493d3b
6
+ metadata.gz: ac1dd30628176e9f5feb4f461bd4a4931050967945be9f81e1e6ceaa4387f52c1139d652a518acf4b2bce5e5309d9c95ccd8d5708215c672975b730e9be20e57
7
+ data.tar.gz: f77ef5d6d8c7d3c8a204f5b053b7a56183c3298f6b8b6a22606257e16febb0087ccb304ad60ed7acd26f3123693b40756503b178096870fd80d705d604f737e6
data/README.md CHANGED
@@ -27,13 +27,15 @@ end
27
27
  class AddressSerializer < Blueprinter::Base
28
28
  identifier :id
29
29
 
30
- fields :address
30
+ field :address
31
31
  end
32
32
 
33
33
  class UserSerializer < Blueprinter::Base
34
34
  identifier :id
35
35
 
36
- fields :name, :email, :created_at
36
+ field :name, description: 'The name of the user'
37
+ fields :email, :created_at
38
+
37
39
  association :addresses, blueprint: AddressSerializer
38
40
  end
39
41
  ```
@@ -58,7 +60,8 @@ BlueprinterSchema.generate(UserSerializer, User)
58
60
  "type" => "string"
59
61
  },
60
62
  "name" => {
61
- "type" => ["string", "null"]
63
+ "type" => ["string", "null"],
64
+ 'description' => 'The name of the user'
62
65
  },
63
66
  "addresses" => {
64
67
  "type" => "array",
@@ -91,14 +94,28 @@ BlueprinterSchema.generate(
91
94
  model,
92
95
  {
93
96
  include_conditional_fields: true, # Whether or not to include conditional fields from the serializer
94
- fallback_type: {} # Type when no DB column is found or type is unknown. E.g. { 'type' => 'object' }
97
+ fallback_type: {}, # Type when no DB column is found or type is unknown. E.g. { 'type' => 'object' }
98
+ view: :default # The Blueprint view to use
95
99
  }
96
100
  )
97
101
  ```
98
102
 
99
103
  ## Development
100
104
 
101
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
105
+ Devcontainer / Codespaces / Native
106
+
107
+ ```sh
108
+ bin/setup
109
+ ```
110
+
111
+ Docker
112
+
113
+ ```sh
114
+ docker compose up -d
115
+ docker compose exec ruby bin/setup
116
+ ```
117
+
118
+ Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
102
119
 
103
120
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
104
121
 
data/Rakefile CHANGED
@@ -1,12 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require 'rubocop/rake_task'
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
@@ -2,7 +2,7 @@
2
2
 
3
3
  module BlueprinterSchema
4
4
  class Generator
5
- def initialize(serializer, model, options = { include_conditional_fields: true, fallback_type: {} })
5
+ def initialize(serializer, model, options)
6
6
  @serializer = serializer
7
7
  @model = model
8
8
  @options = options
@@ -21,11 +21,11 @@ module BlueprinterSchema
21
21
  private
22
22
 
23
23
  def fields
24
- @fields ||= @serializer.reflections[:default].fields
24
+ @fields ||= @serializer.reflections[@options[:view]].fields
25
25
  end
26
26
 
27
27
  def associations
28
- @associations ||= @serializer.reflections[:default].associations
28
+ @associations ||= @serializer.reflections[@options[:view]].associations
29
29
  end
30
30
 
31
31
  def build_properties
@@ -45,7 +45,8 @@ module BlueprinterSchema
45
45
  end
46
46
 
47
47
  def skip_field?(field)
48
- !@options[:include_conditional_fields] && (field.options[:if] || field.options[:unless])
48
+ !@options[:include_conditional_fields] &&
49
+ (field.options[:if] || field.options[:unless] || field.options[:exclude_if_nil])
49
50
  end
50
51
 
51
52
  def build_required_fields
@@ -55,7 +56,9 @@ module BlueprinterSchema
55
56
  def field_to_json_schema(field)
56
57
  column = @model.columns_hash[field.name.to_s]
57
58
 
58
- ar_column_to_json_schema(column) || @options[:fallback_type]
59
+ type = ar_column_to_json_schema(column) || @options[:fallback_type]
60
+ type['description'] = field.options[:description] if field.options[:description]
61
+ type
59
62
  end
60
63
 
61
64
  # rubocop:disable Metrics/MethodLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlueprinterSchema
4
- VERSION = '0.4.2'
4
+ VERSION = '0.6.0'
5
5
  end
@@ -4,7 +4,11 @@ require_relative 'blueprinter_schema/version'
4
4
  require_relative 'blueprinter_schema/generator'
5
5
 
6
6
  module BlueprinterSchema
7
- def self.generate(serializer, model, options = { include_conditional_fields: true, fallback_type: {} })
7
+ def self.generate(
8
+ serializer,
9
+ model,
10
+ options = { include_conditional_fields: true, fallback_type: {}, view: :default }
11
+ )
8
12
  Generator.new(serializer, model, options).generate
9
13
  end
10
14
  end
metadata CHANGED
@@ -1,14 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprinter_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thisismydesign
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activerecord
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: blueprinter
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
12
40
  email:
13
41
  - git.thisismydesign@gmail.com
14
42
  executables: []