# frozen_string_literal: true require_relative "meta_programming_common/version" module MetaProgrammingCommon class Error < StandardError; end # Your code goes here... #http://stackoverflow.com/questions/2751857/how-can-i-iterate-through-all-of-the-models-in-my-rails-app # def self.models0(prefix) # [Rails.application] + Rails::Engine.subclasses.collect(&:instance)).flat_map do |app| # (app.paths['app/models'].to_a + app.config.autoload_paths).collect do |load_path| # Dir.glob(app.root.join(load_path)).collect do |load_dir| # Dir.glob(load_dir + '/**/*.rb').collect do |filename| # # app/models/module/class.rb => module/class.rb => module/class => Module::Class # lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize # end # end # end # end#.flatten.reject { |m| m.starts_with?('Concerns::') } # # end # MetaProgrammingCommon.page_models def self.page_models(prefix = "page") models = [] # folder = File.join(Rails.root, "app", "models") # folder = File.join(`pwd`.strip, 'lib') folder = PageParser.gem_lib_root #byebug # add a variable for the generic page parser so it can be included LAST # and, yes, this relies on leaky variable scope; using a tool which is crappy isn't bad # when its standard parser_page_base_filename = File.join(folder, 'parser_page_base.rb') require parser_page_base_filename Dir[File.join(folder, "*")].each do |filename| #byebug next if filename =~ /page_parser_base/ next if filename =~ /parser_page_base/ next if filename =~ /page_archive/ if filename =~ /lib\/#{prefix}/ #byebug # See: late night hacking require filename #puts filename klass = File.basename(filename, '.rb').camelize.constantize models << klass if klass.available? elsif filename =~ /generic/ generic_page_parser = filename end # add in the generic page for handling unknown cased end #byebug #raise models.inspect # should add this to the very end #require generic_page_parser generic_page_parser_filename = File.join(folder, 'page_generic.rb') require generic_page_parser_filename klass = File.basename('page_generic', '.rb').camelize.constantize models << klass if klass.available? #puts models return models end def self.all_page_models(prefix = "page") models = [] folder = File.join(Rails.root, "app", "models") Dir[File.join(folder, "*")].each do |filename| next if filename =~ /page_parser_base/ next if filename =~ /page_archive/ if filename =~ /models\/#{prefix}/ klass = File.basename(filename, '.rb').camelize.constantize models << klass end end return models end end