Class: SpecForge::Attribute::Faker
- Inherits:
-
Parameterized
- Object
- Attribute
- Parameterized
- SpecForge::Attribute::Faker
- Includes:
- Chainable
- Defined in:
- lib/spec_forge/attribute/faker.rb
Overview
Represents an attribute that generates fake data using the Faker gem
This class allows SpecForge to integrate with the Faker library to generate realistic test data like names, emails, addresses, etc.
Constant Summary collapse
- KEYWORD_REGEX =
Regular expression pattern that matches attribute keywords with this prefix Used for identifying this attribute type during parsing
/^faker\./i
Constants included from Chainable
Instance Attribute Summary collapse
-
#faker_class ⇒ Class
readonly
The Faker class.
-
#faker_method ⇒ Method
readonly
The Faker class method.
Attributes included from Chainable
#header, #invocation_chain, #keyword
Attributes inherited from Parameterized
Instance Method Summary collapse
-
#base_object ⇒ Object
Returns the base object for the variable chain.
-
#initialize ⇒ Faker
constructor
Creates a new faker attribute with the specified name and arguments.
Methods included from Chainable
Methods inherited from Parameterized
Constructor Details
#initialize ⇒ Faker
Creates a new faker attribute with the specified name and arguments
49 50 51 52 53 54 55 |
# File 'lib/spec_forge/attribute/faker.rb', line 49 def initialize(...) super @faker_class, @faker_method = extract_faker_call prepare_arguments end |
Instance Attribute Details
#faker_class ⇒ Class (readonly)
Returns The Faker class.
36 37 38 |
# File 'lib/spec_forge/attribute/faker.rb', line 36 def faker_class @faker_class end |
#faker_method ⇒ Method (readonly)
Returns The Faker class method.
39 40 41 |
# File 'lib/spec_forge/attribute/faker.rb', line 39 def faker_method @faker_method end |
Instance Method Details
#base_object ⇒ Object
Returns the base object for the variable chain
62 63 64 65 66 67 68 69 70 |
# File 'lib/spec_forge/attribute/faker.rb', line 62 def base_object if (positional = arguments[:positional]) && positional.present? faker_method.call(*positional.resolved) elsif (keyword = arguments[:keyword]) && keyword.present? faker_method.call(**keyword.resolved) else faker_method.call end end |