<commit_before>module Lingohub
  module Models
    require 'lingohub/models/resource'
    require 'lingohub/models/collaborator'

    class Project
      def self.lazy_attr_accessor(*params)
        params.each do |sym|
          define_method(sym) do
            unless defined? @fetched
              fetch
            end
            self.instance_variable_get("@#{sym}")
          end
          define_method("#{sym}=") do |value|
            self.instance_variable_set("@#{sym}", value)
          end
        end
      end

      lazy_attr_accessor(:title, :link, :weburl, :resources_url, :collaborators_url, :invitations_url, :translations_url, :search_url, :translations_count, :owner)

      def initialize(client, link)
        @client = client
        @link = link
      end

      def create!(attributes={})
        self.title = attributes[:title]
      end

      def destroy
        @client.delete self.link
      end

      def update(attributes={})
        @client.put self.link, {:project => attributes}
      end

      def invite_collaborator(email)
        @client.post(self.invitations_url, :invitation => {:email => email})
      end

      def resources
        unless defined? @resources
          @resources = {}
          response = @client.get(self.resources_url)
          resource_hash = JSON.parse(response)
          members = resource_hash["resources"]["members"]
          members.each do |member|
            @resources[member["name"]] = Lingohub::Models::Resource.new(@client, member["link"]["href"])
          end
        end
        @resources
      end

      def collaborators
        unless defined? @collaborators
          @collaborators = []
          response = @client.get(self.collaborators_url)
          resource_hash = JSON.parse(response)
          members = resource_hash["members"]
          members.each do |member|
            link = member["link"]["href"] rescue ""
            collaborator = Lingohub::Models::Collaborator.new(@client, link)
            collaborator.email = member["email"]
            collaborator.display_name = member["display_name"]
            collaborator.roles = member["roles"]
            @collaborators << collaborator
          end
        end
        @collaborators
      end

      def pull_resource(directory, filename)
        raise "Project does not contain that file." unless self.resources.has_key?(filename)
        save_to_file(File.join(directory, filename), self.resources[filename].content)
      end
<commit_msg> #1 Fix `lingohub translation:down --all ARGS`<commit_after>module Lingohub
  module Models
    require 'lingohub/models/resource'
    require 'lingohub/models/collaborator'

    class Project
      def self.lazy_attr_accessor(*params)
        params.each do |sym|
          define_method(sym) do
            unless defined? @fetched
              fetch
            end
            self.instance_variable_get("@#{sym}")
          end
          define_method("#{sym}=") do |value|
            self.instance_variable_set("@#{sym}", value)
          end
        end
      end

      lazy_attr_accessor(:title, :link, :weburl, :resources_url, :collaborators_url, :invitations_url, :translations_url, :search_url, :translations_count, :owner)

      def initialize(client, link)
        @client = client
        @link = link
      end

      def create!(attributes={})
        self.title = attributes[:title]
      end

      def destroy
        @client.delete self.link
      end

      def update(attributes={})
        @client.put self.link, {:project => attributes}
      end

      def invite_collaborator(email)
        @client.post(self.invitations_url, :invitation => {:email => email})
      end

      def resources
        unless defined? @resources
          @resources = {}
          response = @client.get(self.resources_url)
          resource_hash = JSON.parse(response)
          members = resource_hash["members"]
          members.each do |member|
            @resources[member["name"]] = Lingohub::Models::Resource.new(@client, member["links"][0]["href"])
          end
        end
        @resources
      end

      def collaborators
        unless defined? @collaborators
          @collaborators = []
          response = @client.get(self.collaborators_url)
          resource_hash = JSON.parse(response)
          members = resource_hash["members"]
          members.each do |member|
            link = member["link"]["href"] rescue ""
            collaborator = Lingohub::Models::Collaborator.new(@client, link)
            collaborator.email = member["email"]
            collaborator.display_name = member["display_name"]
            collaborator.roles = member["roles"]
            @collaborators << collaborator
          end
        end
        @collaborators
      end

      def pull_resource(directory, filename)
        raise "Project does not contain that file." unless self.resources.has_key?(filename)
        save_to_file(File.join(directory, filename), self.resources[filename].content)
      end

{'fraction_non_alphanumeric': 0.10634920634920635, 'fraction_numerical': 0.0003968253968253968, 'mean_word_length': 2.2334830019243106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4986722', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1368, 'n_words': 296}