factory_bot_generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e48d0a18a5138212e9933b02a5c2eba49ede8cdb
4
+ data.tar.gz: 155d667b33ac7287b44997329717317496a7ef83
5
+ SHA512:
6
+ metadata.gz: 4bd645ba0074325ece094174d93468b0070c2e5f38c0c43a1f63cfee87b2ddf0744b8e4ab2073957f758819d8645180f29b798d13645f7fec7f98a147f30ac9e
7
+ data.tar.gz: 51b993d3d4f5c155efc7191e9aee43a3834826277323cfbbe13f290a7b7bcdfe46ab47a404ce64233ea4ab15fa6f9d74fdae9aa2337c7b5899665fa139857589
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .idea/
data/.reek.yml ADDED
@@ -0,0 +1,3 @@
1
+ detectors:
2
+ IrresponsibleModule:
3
+ enabled: false
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ Style/Documentation:
4
+ Enabled: false
5
+ Metrics/LineLength:
6
+ Max: 120
7
+ Layout/AlignParameters:
8
+ EnforcedStyle: with_fixed_indentation
9
+ Style/SafeNavigation:
10
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in factory_bot_generator.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ factory_bot_generator (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ axiom-types (0.1.1)
11
+ descendants_tracker (~> 0.0.4)
12
+ ice_nine (~> 0.11.0)
13
+ thread_safe (~> 0.3, >= 0.3.1)
14
+ bundle-audit (0.1.0)
15
+ bundler-audit
16
+ bundler-audit (0.6.0)
17
+ bundler (~> 1.2)
18
+ thor (~> 0.18)
19
+ codeclimate-engine-rb (0.4.1)
20
+ virtus (~> 1.0)
21
+ coercible (1.0.0)
22
+ descendants_tracker (~> 0.0.1)
23
+ descendants_tracker (0.0.4)
24
+ thread_safe (~> 0.3, >= 0.3.1)
25
+ diff-lcs (1.3)
26
+ equalizer (0.0.11)
27
+ ice_nine (0.11.2)
28
+ jaro_winkler (1.5.1)
29
+ kwalify (0.7.2)
30
+ parallel (1.12.1)
31
+ parser (2.5.1.0)
32
+ ast (~> 2.4.0)
33
+ powerpack (0.1.2)
34
+ rainbow (3.0.0)
35
+ rake (10.5.0)
36
+ reek (5.0.1)
37
+ codeclimate-engine-rb (~> 0.4.0)
38
+ kwalify (~> 0.7.0)
39
+ parser (>= 2.5.0.0, < 2.6)
40
+ rainbow (>= 2.0, < 4.0)
41
+ rspec (3.7.0)
42
+ rspec-core (~> 3.7.0)
43
+ rspec-expectations (~> 3.7.0)
44
+ rspec-mocks (~> 3.7.0)
45
+ rspec-core (3.7.1)
46
+ rspec-support (~> 3.7.0)
47
+ rspec-expectations (3.7.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.7.0)
50
+ rspec-mocks (3.7.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.7.0)
53
+ rspec-support (3.7.1)
54
+ rubocop (0.58.1)
55
+ jaro_winkler (~> 1.5.1)
56
+ parallel (~> 1.10)
57
+ parser (>= 2.5, != 2.5.1.1)
58
+ powerpack (~> 0.1)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (~> 1.0, >= 1.0.1)
62
+ ruby-progressbar (1.9.0)
63
+ thor (0.20.0)
64
+ thread_safe (0.3.6)
65
+ unicode-display_width (1.4.0)
66
+ virtus (1.0.5)
67
+ axiom-types (~> 0.1)
68
+ coercible (~> 1.0)
69
+ descendants_tracker (~> 0.0, >= 0.0.3)
70
+ equalizer (~> 0.0, >= 0.0.9)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundle-audit
77
+ bundler (~> 1.16)
78
+ factory_bot_generator!
79
+ rake (~> 10.0)
80
+ reek
81
+ rspec (~> 3.0)
82
+ rubocop
83
+
84
+ BUNDLED WITH
85
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Siarhei Kisliak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # FactoryBotGenerator
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'factory_bot_generator'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install factory_bot_generator
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+
24
+ user = User.first
25
+
26
+ puts FactoryBotGenerator::Base.render(user)
27
+ puts FactoryBotGenerator::Base.render(user, { name: :first_user })
28
+ puts FactoryBotGenerator::Base.render(user, { exclude: [:password, :last_name, :ssn] })
29
+
30
+ ```
31
+
32
+ ## Development
33
+
34
+ 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.
35
+
36
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/factory_bot_generator.
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'factory_bot_generator'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'factory_bot_generator/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'factory_bot_generator'
9
+ spec.version = FactoryBotGenerator::VERSION
10
+ spec.authors = ['Serge Kislak']
11
+ spec.email = ['kislak7@gmail.com']
12
+
13
+ spec.summary = 'Render FactoryBot factory existing object.'
14
+ spec.description = 'Render FactoryBot factory existing object.'
15
+ spec.homepage = ''
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundle-audit'
26
+ spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'reek'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'rubocop'
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FactoryBotGenerator
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'factory_bot_generator/version'
4
+
5
+ module FactoryBotGenerator
6
+ class Base
7
+ QUOTE_AROUND_VALUE_TYPES = %i[string date datetime text].freeze
8
+ EXCLUDE_COLUMNS = %w[created_at updated_at].freeze
9
+
10
+ def self.render(record, options = {})
11
+ new(record, options).render
12
+ end
13
+
14
+ attr_reader :record, :options
15
+
16
+ def initialize(record, options)
17
+ @record = record
18
+ @options = options
19
+ end
20
+
21
+ def render
22
+ ActionView::Base.new(File.dirname(__FILE__)).render(
23
+ file: 'factory_generator.erb',
24
+ locals: {
25
+ name: name,
26
+ columns: columns,
27
+ record: record,
28
+ indent: indent
29
+ }
30
+ )
31
+ end
32
+
33
+ private
34
+
35
+ def name
36
+ options[:name] || record_class.name.underscore
37
+ end
38
+
39
+ def columns
40
+ @columns ||= record_class.column_names - exclude_columns
41
+ end
42
+
43
+ def indent
44
+ @indent ||= columns.max_by(&:size).size
45
+ end
46
+
47
+ def record_class
48
+ record.class
49
+ end
50
+
51
+ def exclude_columns
52
+ @exclude_columns ||= (EXCLUDE_COLUMNS + options[:exclude].to_a.map(&:to_s))
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :<%= name %>, class: <%= record.class %> do
3
+ <% columns.each do |column| %>
4
+ <% quote = FactoryGenerator::QUOTE_AROUND_VALUE_TYPES.include?(record.class.columns_hash[column].type) %>
5
+ <%= "%-#{indent}s" % column %> <%== "'" if quote %><%== record.public_send(column) %><%== "'" if quote %>
6
+ <% end %>
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: factory_bot_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Serge Kislak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundle-audit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: reek
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Render FactoryBot factory existing object.
98
+ email:
99
+ - kislak7@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".reek.yml"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - factory_bot_generator.gemspec
117
+ - lib/factory_bot_generator.rb
118
+ - lib/factory_bot_generator/version.rb
119
+ - lib/factory_generator.erb
120
+ homepage: ''
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.8
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Render FactoryBot factory existing object.
144
+ test_files: []