{"action":"closed","issue":{"url":"https://api.github.com/repos/coverhound/fixturator/issues/8","repository_url":"https://api.github.com/repos/coverhound/fixturator","labels_url":"https://api.github.com/repos/coverhound/fixturator/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/coverhound/fixturator/issues/8/comments","events_url":"https://api.github.com/repos/coverhound/fixturator/issues/8/events","html_url":"https://github.com/coverhound/fixturator/issues/8","id":192176575,"number":8,"title":"Locating all models","user":{"login":"berfarah","id":1395723,"avatar_url":"https://avatars.githubusercontent.com/u/1395723?v=3","gravatar_id":"","url":"https://api.github.com/users/berfarah","html_url":"https://github.com/berfarah","followers_url":"https://api.github.com/users/berfarah/followers","following_url":"https://api.github.com/users/berfarah/following{/other_user}","gists_url":"https://api.github.com/users/berfarah/gists{/gist_id}","starred_url":"https://api.github.com/users/berfarah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/berfarah/subscriptions","organizations_url":"https://api.github.com/users/berfarah/orgs","repos_url":"https://api.github.com/users/berfarah/repos","events_url":"https://api.github.com/users/berfarah/events{/privacy}","received_events_url":"https://api.github.com/users/berfarah/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-29T03:07:30Z","updated_at":"2016-11-29T03:07:58Z","closed_at":"2016-11-29T03:07:58Z","body":"I've extracted the ability to locate all models in your application. However, you're free to add this functionality to your application yourself:\r\n\r\n```rb\r\nmodule Fixturator\r\n  class Locator\r\n    # @param blacklist [Array<ActiveRecord::Base>]\r\n    # @param whitelist [Array<ActiveRecord::Base>]\r\n    # @return models [Array<ActiveRecord::Base>]\r\n    def self.call(*args)\r\n      new(*args).call\r\n    end\r\n\r\n    def initialize(blacklist: [], whitelist: [])\r\n      Rails.application.eager_load!\r\n\r\n      @blacklist = blacklist\r\n      @whitelist = whitelist\r\n      @models = ActiveRecord::Base.descendants - blacklisted\r\n    end\r\n\r\n    def call\r\n      return models & whitelist unless whitelist.empty?\r\n      models.reject!(&:abstract_class) if Rails::VERSION::MAJOR >= 5\r\n      models\r\n    end\r\n\r\n    private\r\n\r\n    attr_reader :models, :blacklist, :whitelist\r\n\r\n    def blacklisted\r\n      [schema_migration] + blacklist\r\n    end\r\n\r\n    def schema_migration\r\n      ActiveRecord::SchemaMigration\r\n    end\r\n  end\r\nend\r\n```\r\n\r\n### Usage:\r\n\r\n```rb\r\n# whitelist will ensure all models are contained in the array\r\n# blacklist will remove the models in the array\r\nLocator.call(blacklist: [], whitelist: [])\r\n# => [User, Post, ...]\r\n```"}}
{"actor":{"display_login":"berfarah"}}