Skip to content

Commit fae884e

Browse files
authored
Merge pull request #62 from BillyRuffian/feature/name-space-factory-classes
bump to v3.0.0. Classes are now always created in the FakerMaker::Factory namespace
2 parents a27e400 + cb19af5 commit fae884e

12 files changed

Lines changed: 50 additions & 42 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,27 @@ name: Ruby
1010
on:
1111
push:
1212
pull_request:
13-
branches: [ "master" ]
13+
branches: ["master"]
1414

1515
permissions:
1616
contents: read
1717

1818
jobs:
1919
test:
20-
2120
runs-on: ubuntu-latest
2221
strategy:
2322
matrix:
24-
ruby-version: ["3.0", "3.1", "3.2"]
23+
ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4"]
2524

2625
steps:
27-
- uses: actions/checkout@v3
28-
- name: Set up Ruby
29-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
30-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
31-
# uses: ruby/setup-ruby@v1
32-
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
33-
with:
34-
ruby-version: ${{ matrix.ruby-version }}
35-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
36-
- name: Run tests
37-
run: bundle exec rake
26+
- uses: actions/checkout@v3
27+
- name: Set up Ruby
28+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
29+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
30+
# uses: ruby/setup-ruby@v1
31+
uses: ruby/setup-ruby@v1 # v1.146.0
32+
with:
33+
ruby-version: ${{ matrix.ruby-version }}
34+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
35+
- name: Run tests
36+
run: bundle exec rake

.rubocop.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Layout/SpaceInsideParens:
22
Enabled: false
33

4-
Metrics/LineLength:
4+
Layout/LineLength:
55
Max: 120
66

77
Metrics/ModuleLength:
@@ -32,7 +32,7 @@ Style/HashEachMethods:
3232

3333
Style/HashTransformKeys:
3434
Enabled: true
35-
35+
3636
Style/HashTransformValues:
3737
Enabled: true
3838

@@ -52,4 +52,4 @@ Metrics/PerceivedComplexity:
5252
Max: 10
5353

5454
AllCops:
55-
NewCops: enable
55+
NewCops: enable

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

77
# Specify your gem's dependencies in faker_maker.gemspec
88
gemspec
9+
10+
gem 'bundler-audit', '~> 0.9.2'
11+
gem 'irb', '~> 1.15'
12+
gem 'rdoc', '~> 6.13'

lib/faker_maker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def shut!( name )
6363
return unless factory
6464

6565
factories[name] = nil
66-
Object.send( :remove_const, factory.class_name )
66+
FakerMaker::Factory.send( :remove_const, factory.class_name )
6767
end
6868

6969
def shut_all!

lib/faker_maker/factory.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize( name, options = {} )
2828

2929
def parent_class
3030
if @parent
31-
Object.const_get( FakerMaker[@parent].class_name )
31+
FakerMaker::Factory.const_get( FakerMaker[@parent].class_name )
3232
else
3333
Object
3434
end
@@ -67,7 +67,7 @@ def build( attributes: {}, chaos: false, **kwargs )
6767
def assemble
6868
if @klass.nil?
6969
@klass = Class.new parent_class
70-
Object.const_set @class_name, @klass
70+
FakerMaker::Factory.const_set @class_name, @klass
7171
attach_attributes_to_class
7272
attach_json_overrides_to_class
7373
end

lib/faker_maker/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module FakerMaker
4-
VERSION = '2.1.2'
4+
VERSION = '3.0.0'
55
end

spec/faker_maker/factory_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
child_attributes.each { |a| child.attach_attribute( a ) }
4444
FakerMaker.register_factory( child )
4545

46-
fake = Child.new
46+
fake = FakerMaker::Factory::Child.new
4747

4848
expect( fake ).to respond_to( :date )
4949
expect( fake ).to respond_to( :title )

spec/faker_maker_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
it 'builds objects from a factory' do
2121
FakerMaker.register_factory(factory)
22-
expect( FakerMaker.build( :placeholder ) ).to be_a Placeholder
22+
expect( FakerMaker.build( :placeholder ) ).to be_a FakerMaker::Factory::Placeholder
2323
end
2424

2525
it 'raises an error if the factory doesn\'t exist' do
@@ -29,10 +29,10 @@
2929
describe '#shut!' do
3030
it 'removes the factory and its class' do
3131
factory = FakerMaker.register_factory( FakerMaker::Factory.new( :shut_me ) )
32-
expect( Object.const_get( factory.class_name) ).not_to be_nil
32+
expect( FakerMaker::Factory.const_get( factory.class_name) ).not_to be_nil
3333
FakerMaker.shut!( factory.name )
3434
expect { FakerMaker[factory.name] }.to raise_error( FakerMaker::NoSuchFactoryError )
35-
expect { Object.const_get( factory.class_name) }.to raise_error( NameError )
35+
expect { FakerMaker::Factory.const_get( factory.class_name) }.to raise_error( NameError )
3636
end
3737
end
3838

@@ -43,7 +43,7 @@
4343
FakerMaker.shut_all!
4444
factories.each do |name, factory|
4545
expect { FakerMaker[name] }.to raise_error( FakerMaker::NoSuchFactoryError )
46-
expect { Object.const_get( factory.class_name) }.to raise_error( NameError )
46+
expect { FakerMaker::Factory.const_get( factory.class_name) }.to raise_error( NameError )
4747
end
4848
end
4949
end

usefakermaker.com/Gemfile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
source "https://rubygems.org"
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
24
# Hello! This is where you manage which Jekyll version is used to run.
35
# When you want to use a different version, change it below, save the
46
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
@@ -7,31 +9,31 @@ source "https://rubygems.org"
79
#
810
# This will help ensure the proper Jekyll version is running.
911
# Happy Jekylling!
10-
gem "jekyll", "~> 4.3.4"
12+
gem 'jekyll', '~> 4.3.4'
1113
# This is the default theme for new Jekyll sites. You may change this to anything you like.
12-
gem "minima", "~> 2.5"
14+
gem 'minima', '~> 2.5'
1315
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
1416
# uncomment the line below. To upgrade, run `bundle update github-pages`.
1517
# gem "github-pages", group: :jekyll_plugins
1618
# If you have any plugins, put them here!
1719
group :jekyll_plugins do
18-
gem "jekyll-feed", "~> 0.12"
19-
gem "jekyll-data"
20+
gem 'jekyll-data'
21+
gem 'jekyll-feed', '~> 0.12'
2022
end
2123

2224
# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
2325
# and associated library.
2426
platforms :mingw, :x64_mingw, :mswin, :jruby do
25-
gem "tzinfo", ">= 1", "< 3"
26-
gem "tzinfo-data"
27+
gem 'tzinfo', '>= 1', '< 3'
28+
gem 'tzinfo-data'
2729
end
2830

2931
# Performance-booster for watching directories on Windows
30-
gem "wdm", "~> 0.1", :platforms => [:mingw, :x64_mingw, :mswin]
32+
gem 'wdm', '~> 0.1', platforms: %i[mingw x64_mingw mswin]
3133

3234
# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
3335
# do not have a Java counterpart.
34-
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]
35-
gem "minimal-mistakes-jekyll"
3636
gem 'base64'
3737
gem 'csv'
38+
gem 'http_parser.rb', '~> 0.6.0', platforms: [:jruby]
39+
gem 'minimal-mistakes-jekyll'

usefakermaker.com/docs/usage/building-instances/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To build an object:
1111
result = FakerMaker[:basket].build
1212
```
1313

14-
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.
14+
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.
1515

1616
It's possible to override attributes at build-time, either by passing values as a hash:
1717

0 commit comments

Comments
 (0)