<commit_before>require 'dm-types/uuid'
require 'dm-types/yaml'

require 'yogo/configuration'

module Yogo
  module Collection
    class Property
      include DataMapper::Resource

      property  :id,      UUID,         :key => true, :default => lambda { Configuration.random_uuid }
      property  :name,    String,       :required => true
      property  :options, Yaml,         :default => {}.to_yaml
      property  :type,    Discriminator
      
      property   :data_collection_id, UUID
      belongs_to :data_collection, :model => 'Yogo::Collection::Data'
      
    
      def field_name
        self.name
      end
    
      def to_s
        'field_' + self.id.to_s.gsub('-','_')
      end
      
      def model_method
        :property
      end
      
      def add_to_model(model)
        prop_name = self.to_s.intern
        prop_type = self.class
        prop_options   = self.options || {}
        
        model.send(model_method, prop_name, prop_type, prop_options)
      end
      
      class String < self; end
      class Integer < self; end
      
    end # Property
    
    
    class Relationship < Property
      property :target,       String
      property :cardinality,  Integer,    :default => 1
      
      def model_method
        :has
      end
      
      def check_target
        raise ":target not set" unless self.target && !self.target.empty?
      end
      
      def add_to_model(model)
        check_target
        model.send(model_method, cardinality, ActiveSupport::Inflector.tableize(self.target).intern, self.options)
      end
      
      class ManyToMany < self; end
      
      class OneToMany < self; end
      
      class OneToOne < self; end<commit_msg>Generate common properties<commit_after>require 'dm-types/uuid'
require 'dm-types/yaml'

require 'yogo/configuration'

module Yogo
  module Collection
    class Property
      include DataMapper::Resource

      property  :id,      UUID,         :key => true, :default => lambda { Configuration.random_uuid }
      property  :name,    String,       :required => true
      property  :options, Yaml,         :default => {}.to_yaml
      property  :type,    Discriminator
      
      property   :data_collection_id, UUID
      belongs_to :data_collection, :model => 'Yogo::Collection::Data'
      
    
      def field_name
        self.name
      end
    
      def to_s
        'field_' + self.id.to_s.gsub('-','_')
      end
      
      def model_method
        :property
      end
      
      def add_to_model(model)
        prop_name = self.to_s.intern
        prop_type = self.class
        prop_options   = self.options || {}
        
        model.send(model_method, prop_name, prop_type, prop_options)
      end
      
      COMMON_PROPERTIES = [:String, :Text, :Integer, :Float, :Boolean, :Date, :Time, :DateTime]
      COMMON_PROPERTIES.each do |type|
        class_eval %{
        class #{type} < Property; end
        }
      end
    end # Property
    
    
    class Relationship < Property
      property :target,       String
      property :cardinality,  Integer,    :default => 1
      
      def model_method
        :has
      end
      
      def check_target
        raise ":target not set" unless self.target && !self.target.empty?
      end
      
      def add_to_model(model)
        check_target
        model.send(model_method, cardinality, ActiveSupport::Inflector.tableize(self.target).intern, self.options)
      end
      
      class ManyToMany < self; end
      
      class OneToMany < self; end
      
      class OneToOne < self; end
{'fraction_non_alphanumeric': 0.08561070831009482, 'fraction_numerical': 0.0005577244841048522, 'mean_word_length': 1.8673061550759393, 'pattern_counts': {'":': 2, '<': 14, '<?xml version=': 0, '>': 15, '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': '6516601', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1050, 'n_words': 257}