mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
a56b68bc9c
* Alphabetize gem listing in various Gemfiles [Rubocop Bundler/OrderedGems] * Fix alignment of if/else/end statement [Rubocop Layout/ElseAlignment] * Method definitions should have a empty line between them [Rubocop Layout/EmptyLineBetweenDefs] * Modules, Classes, and blocks should have an empty line around them [Rubocop] Cops: Layout/EmptyLinesAroundBlockBody Layout/EmptyLinesAroundModuleBody Layout/EmptyLinesAroundClassBody Layout/EmptyLinesAroundAccessModifier * Keep a blank line before and after access modifiers [Rubocop Layout/EmptyLinesAroundAccessModifier] * Remove misc extra whitespace [Rubocop Layout/ExtraSpacing] * Indent the first line of the right-hand-side of a multi-line assignment [Rubocop Layout/IndentAssignment] * Remove extraneous whitespace [Rubocop] Cops: Layout/IndentationWidth Layout/LeadingCommentSpace Layout/SpaceAroundEqualsInParameterDefault Layout/SpaceInsideArrayLiteralBrackets Layout/SpaceInsideBlockBraces Layout/SpaceInsideParens Layout/TrailingBlankLines * Revert rubocop changes to gemfiles; exclude files from rubocop checks The files in gemfiles/ are generated by Appraisal, so we shouldn't edit them. Instead, let's tell RuboCop to exclude this directory.
31 lines
634 B
Ruby
31 lines
634 B
Ruby
module FactoryBot
|
|
# @api private
|
|
class Trait
|
|
attr_reader :name, :definition
|
|
|
|
def initialize(name, &block)
|
|
@name = name
|
|
@block = block
|
|
@definition = Definition.new(@name)
|
|
|
|
proxy = FactoryBot::DefinitionProxy.new(@definition)
|
|
proxy.instance_eval(&@block) if block_given?
|
|
end
|
|
|
|
delegate :add_callback, :declare_attribute, :to_create, :define_trait, :constructor,
|
|
:callbacks, :attributes, to: :@definition
|
|
|
|
def names
|
|
[@name]
|
|
end
|
|
|
|
def ==(other)
|
|
name == other.name &&
|
|
block == other.block
|
|
end
|
|
|
|
protected
|
|
|
|
attr_reader :block
|
|
end
|
|
end
|