Class: FakerMaker::Attribute
- Inherits:
-
Object
- Object
- FakerMaker::Attribute
- Defined in:
- lib/faker_maker/attribute.rb
Overview
Attributes describe the fields of classes
Constant Summary collapse
- DEFAULT_OPTIONAL_WEIGHTING =
0.5
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#embedded_factories ⇒ Object
readonly
Returns the value of attribute embedded_factories.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#optional_weighting ⇒ Object
readonly
Returns the value of attribute optional_weighting.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#translation ⇒ Object
readonly
Returns the value of attribute translation.
Instance Method Summary collapse
- #array? ⇒ Boolean
- #cardinality ⇒ Object
-
#initialize(name, block = nil, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #omit?(value) ⇒ Boolean
- #translation? ⇒ Boolean
Constructor Details
#initialize(name, block = nil, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/faker_maker/attribute.rb', line 10 def initialize( name, block = nil, = {} ) @name = name @block = block || nil @cardinality = [:has] || 1 @translation = [:json] @omit = *[:omit] @array = [:array] == true @embedded_factories = *[:factory] if [:required].to_s.downcase.eql?('true') || [:optional].to_s.downcase.eql?('false') @required = true else @optional = true @optional_weighting = determine_optional_weighting([:optional]) end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def block @block end |
#embedded_factories ⇒ Object (readonly)
Returns the value of attribute embedded_factories.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def @embedded_factories end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def name @name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def optional @optional end |
#optional_weighting ⇒ Object (readonly)
Returns the value of attribute optional_weighting.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def optional_weighting @optional_weighting end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def required @required end |
#translation ⇒ Object (readonly)
Returns the value of attribute translation.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def translation @translation end |
Instance Method Details
#array? ⇒ Boolean
28 29 30 |
# File 'lib/faker_maker/attribute.rb', line 28 def array? forced_array? || @array end |
#cardinality ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/faker_maker/attribute.rb', line 32 def cardinality if @cardinality.is_a? Range rand( @cardinality ) else @cardinality end end |
#omit?(value) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/faker_maker/attribute.rb', line 44 def omit?( value ) case value when nil @omit.include?( :nil ) || @omit.include?( nil ) when '', [], {} @omit.include? :empty else @omit.include?( :always ) || @omit.include?( value ) end end |
#translation? ⇒ Boolean
40 41 42 |
# File 'lib/faker_maker/attribute.rb', line 40 def translation? !@translation.blank? end |