From 912812247501c9a61107d9eb6eb7fc81b118454d Mon Sep 17 00:00:00 2001 From: Nigel Brookes-Thomas Date: Fri, 25 Apr 2025 14:19:29 +0100 Subject: [PATCH 1/4] bump to v3.0.0. Classes are now always created in the FakerMaker::Factory namespace --- .rubocop.yml | 6 ++--- Gemfile | 4 ++++ lib/faker_maker.rb | 2 +- lib/faker_maker/factory.rb | 4 ++-- lib/faker_maker/version.rb | 2 +- spec/faker_maker/factory_spec.rb | 2 +- spec/faker_maker_spec.rb | 8 +++---- usefakermaker.com/Gemfile | 22 ++++++++++--------- .../docs/usage/building-instances/index.md | 2 +- .../docs/usage/getting-started/index.md | 7 +++--- .../docs/usage/inheritance/index.md | 6 +++-- 11 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 144adb1..64eab7b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ Layout/SpaceInsideParens: Enabled: false -Metrics/LineLength: +Layout/LineLength: Max: 120 Metrics/ModuleLength: @@ -32,7 +32,7 @@ Style/HashEachMethods: Style/HashTransformKeys: Enabled: true - + Style/HashTransformValues: Enabled: true @@ -52,4 +52,4 @@ Metrics/PerceivedComplexity: Max: 10 AllCops: - NewCops: enable \ No newline at end of file + NewCops: enable diff --git a/Gemfile b/Gemfile index cdf3268..03b6049 100644 --- a/Gemfile +++ b/Gemfile @@ -6,3 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in faker_maker.gemspec gemspec + +gem 'bundler-audit', '~> 0.9.2' +gem 'irb', '~> 1.15' +gem 'rdoc', '~> 6.13' diff --git a/lib/faker_maker.rb b/lib/faker_maker.rb index cb11c77..50e6d96 100644 --- a/lib/faker_maker.rb +++ b/lib/faker_maker.rb @@ -63,7 +63,7 @@ def shut!( name ) return unless factory factories[name] = nil - Object.send( :remove_const, factory.class_name ) + FakerMaker::Factory.send( :remove_const, factory.class_name ) end def shut_all! diff --git a/lib/faker_maker/factory.rb b/lib/faker_maker/factory.rb index 2692a15..25eb56b 100644 --- a/lib/faker_maker/factory.rb +++ b/lib/faker_maker/factory.rb @@ -28,7 +28,7 @@ def initialize( name, options = {} ) def parent_class if @parent - Object.const_get( FakerMaker[@parent].class_name ) + FakerMaker::Factory.const_get( FakerMaker[@parent].class_name ) else Object end @@ -67,7 +67,7 @@ def build( attributes: {}, chaos: false, **kwargs ) def assemble if @klass.nil? @klass = Class.new parent_class - Object.const_set @class_name, @klass + FakerMaker::Factory.const_set @class_name, @klass attach_attributes_to_class attach_json_overrides_to_class end diff --git a/lib/faker_maker/version.rb b/lib/faker_maker/version.rb index 099e586..b32fc18 100644 --- a/lib/faker_maker/version.rb +++ b/lib/faker_maker/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module FakerMaker - VERSION = '2.1.2' + VERSION = '3.0.0' end diff --git a/spec/faker_maker/factory_spec.rb b/spec/faker_maker/factory_spec.rb index f07abe5..865ddff 100644 --- a/spec/faker_maker/factory_spec.rb +++ b/spec/faker_maker/factory_spec.rb @@ -43,7 +43,7 @@ child_attributes.each { |a| child.attach_attribute( a ) } FakerMaker.register_factory( child ) - fake = Child.new + fake = FakerMaker::Factory::Child.new expect( fake ).to respond_to( :date ) expect( fake ).to respond_to( :title ) diff --git a/spec/faker_maker_spec.rb b/spec/faker_maker_spec.rb index e0ac0e1..6c2197f 100644 --- a/spec/faker_maker_spec.rb +++ b/spec/faker_maker_spec.rb @@ -19,7 +19,7 @@ it 'builds objects from a factory' do FakerMaker.register_factory(factory) - expect( FakerMaker.build( :placeholder ) ).to be_a Placeholder + expect( FakerMaker.build( :placeholder ) ).to be_a FakerMaker::Factory::Placeholder end it 'raises an error if the factory doesn\'t exist' do @@ -29,10 +29,10 @@ describe '#shut!' do it 'removes the factory and its class' do factory = FakerMaker.register_factory( FakerMaker::Factory.new( :shut_me ) ) - expect( Object.const_get( factory.class_name) ).not_to be_nil + expect( FakerMaker::Factory.const_get( factory.class_name) ).not_to be_nil FakerMaker.shut!( factory.name ) expect { FakerMaker[factory.name] }.to raise_error( FakerMaker::NoSuchFactoryError ) - expect { Object.const_get( factory.class_name) }.to raise_error( NameError ) + expect { FakerMaker::Factory.const_get( factory.class_name) }.to raise_error( NameError ) end end @@ -43,7 +43,7 @@ FakerMaker.shut_all! factories.each do |name, factory| expect { FakerMaker[name] }.to raise_error( FakerMaker::NoSuchFactoryError ) - expect { Object.const_get( factory.class_name) }.to raise_error( NameError ) + expect { FakerMaker::Factory.const_get( factory.class_name) }.to raise_error( NameError ) end end end diff --git a/usefakermaker.com/Gemfile b/usefakermaker.com/Gemfile index 7910c7c..024a10a 100644 --- a/usefakermaker.com/Gemfile +++ b/usefakermaker.com/Gemfile @@ -1,4 +1,6 @@ -source "https://rubygems.org" +# frozen_string_literal: true + +source 'https://rubygems.org' # Hello! This is where you manage which Jekyll version is used to run. # When you want to use a different version, change it below, save the # file and run `bundle install`. Run Jekyll with `bundle exec`, like so: @@ -7,31 +9,31 @@ source "https://rubygems.org" # # This will help ensure the proper Jekyll version is running. # Happy Jekylling! -gem "jekyll", "~> 4.3.4" +gem 'jekyll', '~> 4.3.4' # This is the default theme for new Jekyll sites. You may change this to anything you like. -gem "minima", "~> 2.5" +gem 'minima', '~> 2.5' # If you want to use GitHub Pages, remove the "gem "jekyll"" above and # uncomment the line below. To upgrade, run `bundle update github-pages`. # gem "github-pages", group: :jekyll_plugins # If you have any plugins, put them here! group :jekyll_plugins do - gem "jekyll-feed", "~> 0.12" - gem "jekyll-data" + gem 'jekyll-data' + gem 'jekyll-feed', '~> 0.12' end # Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem # and associated library. platforms :mingw, :x64_mingw, :mswin, :jruby do - gem "tzinfo", ">= 1", "< 3" - gem "tzinfo-data" + gem 'tzinfo', '>= 1', '< 3' + gem 'tzinfo-data' end # Performance-booster for watching directories on Windows -gem "wdm", "~> 0.1", :platforms => [:mingw, :x64_mingw, :mswin] +gem 'wdm', '~> 0.1', platforms: %i[mingw x64_mingw mswin] # Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem # do not have a Java counterpart. -gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby] -gem "minimal-mistakes-jekyll" gem 'base64' gem 'csv' +gem 'http_parser.rb', '~> 0.6.0', platforms: [:jruby] +gem 'minimal-mistakes-jekyll' diff --git a/usefakermaker.com/docs/usage/building-instances/index.md b/usefakermaker.com/docs/usage/building-instances/index.md index 54b50ea..3152633 100644 --- a/usefakermaker.com/docs/usage/building-instances/index.md +++ b/usefakermaker.com/docs/usage/building-instances/index.md @@ -11,7 +11,7 @@ To build an object: result = FakerMaker[:basket].build ``` -will generate a new instance using the Basket factory. Because an actual class is defined, you can instantiate an object directly through `Basket.new` but that will not populate any of the attributes. +will generate a new instance using the Basket factory. Because an actual class is defined (since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace), you can instantiate an object directly through `Basket.new` but that will not populate any of the attributes. It's possible to override attributes at build-time, either by passing values as a hash: diff --git a/usefakermaker.com/docs/usage/getting-started/index.md b/usefakermaker.com/docs/usage/getting-started/index.md index 9e8b50c..cbfc829 100644 --- a/usefakermaker.com/docs/usage/getting-started/index.md +++ b/usefakermaker.com/docs/usage/getting-started/index.md @@ -13,9 +13,10 @@ FakerMaker.factory :user do end ``` -This will generate a `User` class with the attributes `name`, `email` and `admin` which will always return the same value. +This will generate a `FakerMaker::Factory::User` class with the attributes `name`, `email` and `admin` which will always return the same value. +Since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace. -It is possible to explicitly set the name of class which is particularly useful if there is a risk of redefining an existing one. +It is possible to explicitly set the name of class which is particularly useful if there is a risk of redefining an existing one. Classes will **always** be created within the `FakerMaker::Factory` namespace (since v3.0.0) ```ruby FakerMaker.factory :user, class: 'EmailUser' do @@ -25,7 +26,7 @@ FakerMaker.factory :user, class: 'EmailUser' do end ``` -The class name will always be turned into a Ruby-style class name so `email_user` would become `EmailUser`. +The class name will always be turned into a Ruby-style class name so `email_user` would become `FakerMaker::Factory::EmailUser`. Because of the block syntax in Ruby, defining attributes as `Hash`es requires two sets of curly brackets: diff --git a/usefakermaker.com/docs/usage/inheritance/index.md b/usefakermaker.com/docs/usage/inheritance/index.md index 0b6dde5..8616093 100644 --- a/usefakermaker.com/docs/usage/inheritance/index.md +++ b/usefakermaker.com/docs/usage/inheritance/index.md @@ -20,12 +20,14 @@ end This is the equivalent of: +Since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace. + ```ruby -class Vehicle < Object +class FakerMaker::Factory::Vehicle < Object # ... end -class Motorbike < Vehicle +class FakerMaker::Factory::Motorbike < FakerMaker::Factory::Vehicle # ... end ``` From 1ea65286e9d3f219cc4471eeb637c9ae6f626004 Mon Sep 17 00:00:00 2001 From: Nigel Brookes-Thomas Date: Fri, 25 Apr 2025 14:22:13 +0100 Subject: [PATCH 2/4] include ruby 3.3 and 3.4 in tests --- .github/workflows/ruby.yml | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8b0414c..feae506 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -10,28 +10,27 @@ name: Ruby on: push: pull_request: - branches: [ "master" ] + branches: ["master"] permissions: contents: read jobs: test: - runs-on: ubuntu-latest strategy: matrix: - ruby-version: ["3.0", "3.1", "3.2"] + ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4"] steps: - - uses: actions/checkout@v3 - - name: Set up Ruby - # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, - # change this to (see https://github.com/ruby/setup-ruby#versioning): - # uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - name: Run tests - run: bundle exec rake + - uses: actions/checkout@v3 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run tests + run: bundle exec rake From f8a8033ec8a5cb2ca3e5acf280471e02bb41204e Mon Sep 17 00:00:00 2001 From: Nigel Brookes-Thomas Date: Fri, 25 Apr 2025 14:25:10 +0100 Subject: [PATCH 3/4] change workflow to ubuntu 24.04 --- .github/workflows/ruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index feae506..7941b2a 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -17,7 +17,7 @@ permissions: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 strategy: matrix: ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4"] From cb19af5ecfcfda2684ef262646914c06ff34cbc5 Mon Sep 17 00:00:00 2001 From: Nigel Brookes-Thomas Date: Fri, 25 Apr 2025 14:27:09 +0100 Subject: [PATCH 4/4] revert and use v1 workflow ruby image --- .github/workflows/ruby.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 7941b2a..fecd04e 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -17,7 +17,7 @@ permissions: jobs: test: - runs-on: ubuntu-24.04 + runs-on: ubuntu-latest strategy: matrix: ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4"] @@ -28,7 +28,7 @@ jobs: # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, # change this to (see https://github.com/ruby/setup-ruby#versioning): # uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 + uses: ruby/setup-ruby@v1 # v1.146.0 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically