class FakerMaker::Attribute
Attributes describe the fields of classes
Attributes
block[R]
name[R]
translation[R]
Public Class Methods
new( name, block = nil, options = {} )
click to toggle source
# File lib/faker_maker/attribute.rb, line 8 def initialize( name, block = nil, options = {} ) assert_valid_options options @name = name @block = block || proc { nil } @cardinality = options[:has] || 1 @translation = options[:json] @omit = *options[:omit] @array = options[:array] == true end
Public Instance Methods
array?()
click to toggle source
# File lib/faker_maker/attribute.rb, line 18 def array? forced_array? || @array end
cardinality()
click to toggle source
# File lib/faker_maker/attribute.rb, line 22 def cardinality if @cardinality.is_a? Range rand( @cardinality ) else @cardinality end end
omit?( value )
click to toggle source
# File lib/faker_maker/attribute.rb, line 34 def omit?( value ) case value when nil @omit.include? :nil when '', [], {} @omit.include? :empty else @omit.include?( :always ) || @omit.include?( value ) end end
translation?()
click to toggle source
# File lib/faker_maker/attribute.rb, line 30 def translation? !@translation.blank? end
Private Instance Methods
assert_valid_options( options )
click to toggle source
# File lib/faker_maker/attribute.rb, line 51 def assert_valid_options( options ) options.assert_valid_keys :has, :array, :json, :omit end
forced_array?()
click to toggle source
# File lib/faker_maker/attribute.rb, line 47 def forced_array? @cardinality.is_a?( Range ) || @cardinality > 1 end