<commit_before>module Moria
  # A constraint, created by a ConstraintBuilder.
  # A view constraint contains two view attribute (view, attribute) and a relation (>=, == or <=).
  class ViewConstraint
    attr_accessor :first_view_attribute
    attr_accessor :second_view_attribute

    attr_accessor :priority
    attr_accessor :relation
    attr_accessor :multiplier
    attr_accessor :constant

    attr_accessor :installed_view
    attr_accessor :layout_constraint

    def initialize(view_attribute)
      self.first_view_attribute = view_attribute
      self.priority             = UILayoutPriorityRequired
      self.multiplier           = 1.0
      self.constant             = 0.0
    end

    # install constraint on view
    def install
      first_view              = first_view_attribute.view
      first_layout_attribute  = first_view_attribute.layout_attribute
      second_view             = second_view_attribute.view
      second_layout_attribute = second_view_attribute.layout_attribute

      if first_view_attribute.alignment_attribute? && second_view_attribute.nil?
        raise "alignment attributes must have a second_view_attribute: #{self}"
      end

      constraint = NSLayoutConstraint.constraintWithItem(first_view, attribute:first_layout_attribute, relatedBy:self.relation, toItem:second_view, 
          attribute: second_layout_attribute, multiplier:self.multiplier, constant: self.constant)
      constraint.priority = self.priority

      if second_layout_attribute
        closest_common_superview = first_view.closest_common_superview(second_view)
        raise "Cannot install constraint: Could not find a common superview between #{first_view} and #{second_view}" unless closest_common_superview
        self.installed_view = WeakRef.new(closest_common_superview)
      else
        self.installed_view = WeakRef.new(first_view)
      end

      self.installed_view.addConstraint(constraint)
      self.layout_constraint = constraint
    end
    
    def ==(another)
      # overrided == for the DSL
      if another.is_a?(ViewAttribute)
        self.second_view_attribute = another
        self.relation = NSLayoutRelationEqual
        return self
      end

      if another.is_a?(ViewConstraint)
        first_view_attribute == another.first_view_attribute && 
          second_view_attribute == another.second_view_attribute &&
          relation == another.relation<commit_msg>remove the WeakRef in ViewConstraint<commit_after>module Moria
  # A constraint, created by a ConstraintBuilder.
  # A view constraint contains two view attribute (view, attribute) and a relation (>=, == or <=).
  class ViewConstraint
    attr_accessor :first_view_attribute
    attr_accessor :second_view_attribute

    attr_accessor :priority
    attr_accessor :relation
    attr_accessor :multiplier
    attr_accessor :constant

    attr_accessor :installed_view
    attr_accessor :layout_constraint

    def initialize(view_attribute)
      self.first_view_attribute = view_attribute
      self.priority             = UILayoutPriorityRequired
      self.multiplier           = 1.0
      self.constant             = 0.0
    end

    # install constraint on view
    def install
      first_view              = first_view_attribute.view
      first_layout_attribute  = first_view_attribute.layout_attribute
      second_view             = second_view_attribute.view
      second_layout_attribute = second_view_attribute.layout_attribute

      if first_view_attribute.alignment_attribute? && second_view_attribute.nil?
        raise "alignment attributes must have a second_view_attribute: #{self}"
      end

      constraint = NSLayoutConstraint.constraintWithItem(first_view, attribute:first_layout_attribute, relatedBy:self.relation, toItem:second_view, 
          attribute: second_layout_attribute, multiplier:self.multiplier, constant: self.constant)
      constraint.priority = self.priority

      if second_layout_attribute
        closest_common_superview = first_view.closest_common_superview(second_view)
        raise "Cannot install constraint: Could not find a common superview between #{first_view} and #{second_view}" unless closest_common_superview
        self.installed_view = closest_common_superview
      else
        self.installed_view = first_view
      end

      self.installed_view.addConstraint(constraint)
      self.layout_constraint = constraint
    end
    
    def ==(another)
      # overrided == for the DSL
      if another.is_a?(ViewAttribute)
        self.second_view_attribute = another
        self.relation = NSLayoutRelationEqual
        return self
      end

      if another.is_a?(ViewConstraint)
        first_view_attribute == another.first_view_attribute && 
          second_view_attribute == another.second_view_attribute &&
          relation == another.relation
{'fraction_non_alphanumeric': 0.05827650340979541, 'fraction_numerical': 0.0016532341392849763, 'mean_word_length': 3.2270742358078603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6316910', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1249, 'n_words': 287}