class SmartSeeds::Generator::Faker
Public Class Methods
new(column, model)
click to toggle source
Calls superclass method
SmartSeeds::Generator::Base::new
# File lib/smart_seeds/generator/faker.rb, line 6 def initialize(column, model) super end
Public Instance Methods
generate_value()
click to toggle source
# File lib/smart_seeds/generator/faker.rb, line 10 def generate_value faker_class.send(column.name.to_sym) end
is_compatible?()
click to toggle source
# File lib/smart_seeds/generator/faker.rb, line 14 def is_compatible? true if faker_classes_include_model_name? && faker_methods_include_column_name? end
Private Instance Methods
faker_class()
click to toggle source
# File lib/smart_seeds/generator/faker.rb, line 38 def faker_class "Faker::#{model.name.capitalize}".constantize end
faker_classes_include_model_name?()
click to toggle source
# File lib/smart_seeds/generator/faker.rb, line 20 def faker_classes_include_model_name? # Check if Faker has a Class which called as an AR Model faker_classes = ::Faker.constants.select {|c| ::Faker.const_get(c).is_a? Class} faker_classes.include? model.name.to_sym end
faker_methods_include_column_name?()
click to toggle source
# File lib/smart_seeds/generator/faker.rb, line 26 def faker_methods_include_column_name? # Support methods are included in Faker generate class support_singleton_methods = %i(method_missing fetch translate parse with_locale unique numerify letterify bothify regexify fetch_all flexible rand_in_range yaml_tag) klass = faker_class # Here is should stay only methods for generating random values without support methods like: # => [:name, :prefix, :suffix, :power, :descriptor] faker_methods = klass.singleton_methods - support_singleton_methods faker_methods.include? column.name.to_sym end