class Developer < ActiveRecord::Base
  devise :database_authenticatable, :trackable, :validatable, :omniauthable
  store_accessor :data, :bio, :html_url, :avatar_url, :company,
  :blog, :location, :followers, :public_gists, :public_repos, :email, :hireable

  def self.whitelisted_attributes
    all_attributes - protected_attributes
  end

  def self.default_scope
    select(whitelisted_attributes)
  end

  private

  def self.all_attributes
    self.columns.map(&:name).map(&:to_sym)
  end

  def self.protected_attributes
    [:access_token, :provider, :uid, :email]
  end
end

class Developer < ActiveRecord::Base
  devise :database_authenticatable, :trackable, :validatable, :omniauthable
  store_accessor :data, :bio, :html_url, :avatar_url, :company,
  :blog, :location, :followers, :public_gists, :public_repos, :hireable

  after_commit :cache_login!

  def self.fetch_by_login(username)
    premium = REDIS.sismember('hireables:developers_logins', username)

    if premium
      developer =  find_by(login: username)
      Rails.cache.fetch([username, developer], expires_in: 2.days) do
        developer
      end
    else
      self.fetch_from_github(username)
    end
  end

  def self.fetch_from_github(username)
    Rails.cache.fetch(username, expires_in: 2.days) do
      request = Github::Api.new("/users/#{username}").fetch
      response = Github::Response.new(request)
      if response.found?
        JSON.parse(request.body, object_class: OpenStruct)
      else
        raise ActiveRecord::RecordNotFound.new('Not Found')
      end
    end
  end

  def self.fetch_languages_from_github(username)
    Rails.cache.fetch([username, 'languages'], expires_in: 2.days) do
      request = Github::Api.new("/users/#{username}/repos").fetch
      response = Github::Response.new(request)

      if response.found?
        response.developer_languages_collection
      else
        raise ActiveRecord::RecordNotFound.new('Not Found')
      end
    end
  end

  private

  def cache_login
    REDIS.sadd('hireables:developers_logins', login)
  end
end

Remove scope code as we are using Graphql
Remove scope code as we are using Graphql
