Sha256: 46270dc0cefd100483b9c000d0d9d5285219c7914e8757760d331f1733db23b8

Contents?: true

Size: 740 Bytes

Versions: 2

Compression:

Stored size: 740 Bytes

Contents

require 'fantasy_faker/utils/array_utils'

module FantasyFaker

  module BaseModule

    def const_missing(const_name)
      file_content = File.readlines(data_path(const_name)).map(&:strip)
      data         = FantasyFaker::ArrayUtils.const_array(file_content)

      const_set(const_name, data)
      data
    end

    def data_path(file_name)
      "#{FantasyFaker::BASE_LIB_PATH}/fantasy_faker/data/#{underscore(module_name)}/#{underscore(file_name.to_s)}"
    end

    def module_name
      ancestors.first.to_s.split('::').last
    end

    def underscore(string)
      string.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fantasy_faker-0.0.3 lib/fantasy_faker/utils/base_module.rb
fantasy_faker-0.0.2 lib/fantasy_faker/utils/base_module.rb