faker_maker 1.1.9 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9de2b8d5e7f4753789d7c41f7ac37ebb7943fca44d12d1d14a474078dc9ab902
4
- data.tar.gz: 7853d0fe9adee31a5175a2da6101099774b489c6dbed96d56f9fb82afd893204
3
+ metadata.gz: 1b3913f6f52a9519d1b25770428e7a4789845c9115f9b34ffac7347141d80c6c
4
+ data.tar.gz: edf41922350fa0ea7a28561822ed834edddd724ac82f6ecb6bb89fdba18d5c4a
5
5
  SHA512:
6
- metadata.gz: 3dc584ed0bbe6a758bb21308059393833a47a60c014370996ff83b202e9183285a981f31e7ab9c2cbf768435b810fcece7568e5cecd613245b261827aa1ffeeb
7
- data.tar.gz: e62ca83bddc73d1a0edc9cfc9b90356749e62bc0734c0732c7fead6562693ff19353635e63ff6484fdb54eb7dc1faa314497456ea8480b93511f3e36d9079cf2
6
+ metadata.gz: d3d6f954a378a1198f4523e188208059b2d2859b2af0ab0e2d89a00373ee03c5a1baca7289b8c0538bee03652963b361450435efa13dfab7dbd84f68945c6c6a
7
+ data.tar.gz: ea8fed86a1715e39245e5459f70c293b02febf76c4b806858ebddd0d4879dac7d07caadd565d32396165747d355d7099c428258c48526d72e0586114342b86b2
@@ -35,3 +35,12 @@ Style/HashTransformKeys:
35
35
 
36
36
  Style/HashTransformValues:
37
37
  Enabled: true
38
+
39
+ Metrics/AbcSize:
40
+ Enabled: false
41
+
42
+ Metrics/MethodLength:
43
+ Enabled: false
44
+
45
+ Lint/MissingSuper:
46
+ Enabled: false
data/README.md CHANGED
@@ -12,6 +12,7 @@
12
12
  <div align="center">
13
13
 
14
14
  [![Gem Version](https://badge.fury.io/rb/faker_maker.svg)](https://badge.fury.io/rb/faker_maker)
15
+ [![Downloads](https://img.shields.io/gem/dt/faker_maker)](https://rubygems.org/gems/faker_maker)
15
16
  ![CircleCI branch](https://img.shields.io/circleci/project/github/BillyRuffian/faker_maker/master.svg?style=flat-square)
16
17
  [![CodeFactor](https://www.codefactor.io/repository/github/billyruffian/faker_maker/badge?style=flat-square)](https://www.codefactor.io/repository/github/billyruffian/faker_maker)
17
18
  ![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/BillyRuffian/faker_maker.svg?style=flat-square)
@@ -20,4 +21,4 @@
20
21
 
21
22
  FakerMaker is a simple factory builder so you can throw away your fixtures and generate test data instead.
22
23
 
23
- Read the [documentation here](https://billyruffian.github.io/faker_maker/).
24
+ Read the [documentation here](https://billyruffian.github.io/faker_maker/).
@@ -9,21 +9,49 @@ nav_order: 4
9
9
 
10
10
  JavaScript likes to use camelCase, Ruby's idiom is to use snake_case. This can make make manipulating factory-built objects in ruby ugly. To avoid this, you can call your fields one thing and ask the JSON outputter to rename the field when generating JSON.
11
11
 
12
+ Faker Maker provides two mechanisms for dealing with this.
13
+
14
+ ## Factory-wide attribute name re-writing (since 1.1.10)
15
+
16
+ Using the `:naming` option to the factory, you can specify a naming strategy. Currently supported are:
17
+
18
+ * `:json` camelCase with lowercase first letter
19
+ * `:json_capitalized` CamelCase with uppercase first letter
20
+
12
21
  ```ruby
13
- FakerMaker.factory :vehicle do
22
+ FakerMaker.factory :vehicle, naming: :json do
14
23
  wheels { 4 }
15
24
  colour { Faker::Color.color_name }
16
- engine_capacity(json: 'engineCapacity') { rand( 600..2500 ) }
25
+ engine_capacity { rand( 600..2500 ) }
17
26
  end
18
27
 
19
28
  v = FM[:vehicle].build
20
29
  v.engine_capacity = 125
30
+
31
+ v.to_json
32
+
33
+ => "{\"wheels\":4,\"colour\":\"blue\",\"engineCapacity\":125}"
21
34
  ```
22
35
 
23
- and calls to `as_json` and `to_json` will report the fieldname as `engineCapacity`.
36
+ ## Per-attribute naming
37
+
38
+ You can override the name of the attribute on the individual attribute level.
24
39
 
25
40
  ```ruby
41
+ FakerMaker.factory :vehicle do
42
+ wheels { 4 }
43
+ colour { Faker::Color.color_name }
44
+ engine_capacity(json: 'engineCapacity') { rand( 600..2500 ) }
45
+ end
46
+
47
+ v = FM[:vehicle].build
48
+ v.engine_capacity = 125
49
+
26
50
  v.to_json
27
51
 
28
52
  => "{\"wheels\":4,\"colour\":\"blue\",\"engineCapacity\":125}"
29
- ```
53
+ ```
54
+
55
+ ## Combining the two approaches
56
+
57
+ If the factory has a `:naming` strategy defined and an attribute has its own `:json` name defined, the attribute's `:json` name will take precedence.
@@ -52,7 +52,9 @@ Gem::Specification.new do |spec|
52
52
  spec.add_development_dependency 'pry', '~> 0.12'
53
53
  spec.add_development_dependency 'rake', '~> 13.0'
54
54
  spec.add_development_dependency 'rspec', '~> 3.8'
55
- spec.add_development_dependency 'rubocop', '~> 0.68'
55
+ spec.add_development_dependency 'rubocop', '~> 1.0'
56
56
  spec.add_development_dependency 'simplecov', '~> 0.16'
57
57
  spec.add_development_dependency 'coveralls', '~> 0.8'
58
+
59
+ spec.required_ruby_version = '>= 2.6'
58
60
  end
@@ -9,7 +9,10 @@ require 'faker_maker/base'
9
9
  require 'faker_maker/lifecycle_hooks'
10
10
  require 'faker_maker/definition_proxy'
11
11
  require 'faker_maker/factory'
12
- require 'faker_maker/lifecycle_hooks'
12
+
13
+ require 'faker_maker/naming'
14
+ require 'faker_maker/naming/json'
15
+ require 'faker_maker/naming/json_capitalized'
13
16
  require 'faker_maker/version'
14
17
 
15
18
  # FakerMaker module for generating Fakes
@@ -19,6 +22,7 @@ module FakerMaker
19
22
  class Error < StandardError; end
20
23
  class NoSuchFactoryError < StandardError; end
21
24
  class NoSuchAttributeError < StandardError; end
25
+ class NoSuchAttributeNamingStrategy < StandardError; end
22
26
  # Your code goes here...
23
27
 
24
28
  module_function
@@ -13,7 +13,7 @@ module FakerMaker
13
13
  @factory
14
14
  end
15
15
 
16
- def method_missing(name, *args, &block) # rubocop:disable Style/MethodMissingSuper
16
+ def method_missing(name, *args, &block)
17
17
  attribute = FakerMaker::Attribute.new name, block, *args
18
18
  @factory.attach_attribute attribute
19
19
  end
@@ -10,6 +10,16 @@ module FakerMaker
10
10
  assert_valid_options options
11
11
  @name = name.respond_to?(:to_sym) ? name.to_sym : name.to_s.underscore.to_sym
12
12
  @class_name = (options[:class] || @name).to_s.camelcase
13
+ @naming_strategy = case options[:naming]
14
+ when :json
15
+ FakerMaker::Naming::JSON
16
+ when :json_capitalized, :json_capitalised
17
+ FakerMaker::Naming::JSONCapitalized
18
+ when nil
19
+ nil
20
+ else
21
+ raise FakerMaker::NoSuchAttributeNamingStrategy, opttions[:naming]
22
+ end
13
23
  @attributes = []
14
24
  @klass = nil
15
25
  @parent = options[:parent]
@@ -68,7 +78,14 @@ module FakerMaker
68
78
  @json_key_map = {}.with_indifferent_access
69
79
  @json_key_map.merge!( FakerMaker[parent].json_key_map ) if parent?
70
80
  attributes.each_with_object( @json_key_map ) do |attr, map|
71
- key = attr.translation? ? attr.translation : attr.name
81
+ key = if attr.translation?
82
+ attr.translation
83
+ elsif @naming_strategy
84
+ @naming_strategy.name(attr.name)
85
+ else
86
+ attr.name
87
+ end
88
+
72
89
  map[attr.name] = key
73
90
  end
74
91
  end
@@ -143,7 +160,7 @@ module FakerMaker
143
160
  end
144
161
 
145
162
  def assert_valid_options( options )
146
- options.assert_valid_keys :class, :parent
163
+ options.assert_valid_keys :class, :parent, :naming
147
164
  end
148
165
  end
149
166
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FakerMaker
4
+ # Base module for naming strategies
5
+ module Naming
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FakerMaker
4
+ module Naming
5
+ # Use camelCase for naming
6
+ module JSON
7
+ def self.name(name)
8
+ name.to_s.camelize(:lower)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FakerMaker
4
+ module Naming
5
+ # Use CamelCase for naming
6
+ module JSONCapitalized
7
+ def self.name(name)
8
+ name.to_s.camelize
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FakerMaker
4
- VERSION = '1.1.9'
4
+ VERSION = '1.1.10'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faker_maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Brookes-Thomas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -162,14 +162,14 @@ dependencies:
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: '0.68'
165
+ version: '1.0'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '0.68'
172
+ version: '1.0'
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: simplecov
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -246,6 +246,9 @@ files:
246
246
  - lib/faker_maker/definition_proxy.rb
247
247
  - lib/faker_maker/factory.rb
248
248
  - lib/faker_maker/lifecycle_hooks.rb
249
+ - lib/faker_maker/naming.rb
250
+ - lib/faker_maker/naming/json.rb
251
+ - lib/faker_maker/naming/json_capitalized.rb
249
252
  - lib/faker_maker/version.rb
250
253
  homepage: https://billyruffian.github.io/faker_maker/
251
254
  licenses:
@@ -254,7 +257,7 @@ metadata:
254
257
  homepage_uri: https://billyruffian.github.io/faker_maker/
255
258
  source_code_uri: https://github.com/BillyRuffian/faker_maker
256
259
  changelog_uri: https://github.com/BillyRuffian/faker_maker/releases
257
- post_install_message:
260
+ post_install_message:
258
261
  rdoc_options: []
259
262
  require_paths:
260
263
  - lib
@@ -262,15 +265,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
265
  requirements:
263
266
  - - ">="
264
267
  - !ruby/object:Gem::Version
265
- version: '0'
268
+ version: '2.6'
266
269
  required_rubygems_version: !ruby/object:Gem::Requirement
267
270
  requirements:
268
271
  - - ">="
269
272
  - !ruby/object:Gem::Version
270
273
  version: '0'
271
274
  requirements: []
272
- rubygems_version: 3.1.2
273
- signing_key:
275
+ rubygems_version: 3.1.4
276
+ signing_key:
274
277
  specification_version: 4
275
278
  summary: FakerMaker bakes fakes.
276
279
  test_files: []