<commit_before>require File.expand_path("#{File.dirname(__FILE__)}/megam_attributes")
require File.expand_path("#{File.dirname(__FILE__)}/common_deployable")
require File.expand_path("#{File.dirname(__FILE__)}/outputs")

module Megam
  class Mixins
    class Components
      attr_reader :mixins, :name, :repo, :related_components, :operations, :artifacts, :outputs
      def initialize(params)
        @mixins = CommonDeployable.new(params)
        @name = params[:componentname]
        @outputs = Outputs.new(params)
        @operations = add_operations(params)
        @related_components = add_related_components(params)
        @artifacts = add_artifacts(params)
        @repo = add_repo(params)
      end

      def to_hash
        result = @mixins.to_hash
        result[:name]  = @name if @name
        result[:artifacts]  = @artifacts if @artifacts
        result[:repo]  = @repo if @repo
        result[:operations]  = @operations if @operations
        result[:outputs] = @outputs.to_array  if @outputs
        result[:related_components] = @related_components if @related_components
        result
      end

	def to_a
		[to_hash]
	end

      private

      def add_repo(params)
        Repo.new(params).tohash
      end

      def add_related_components(params)
	related_components = []
        related_components << "#{params[:assemblyname]}.#{params[:domain]}/#{params[:componentname]}" if params.key?(:bind_type)
      end

      def add_operations(params)
        operations = []
        operations.push(create_operation(Operations::CI, Operations::CI_DESCRIPTON,  params)) unless params[:scm_name].strip.empty?
        operations.push(create_operation(Operations::BIND, Operations::BIND_DESCRIPTON, params)) if params.key?(:bind_type)
      end

      def create_operation(type, desc, params)
        Operations.new(params, type, desc).tohash
      end

      def add_artifacts(params)
        Artifacts.new(params).tohash
      end
    end

    class Repo
      include Nilavu::MegamAttributes
      attr_reader :type, :source, :url
      ATTRIBUTES = [
        :type,
        :source,
        :oneclick,
        :url]

      def attributes
        ATTRIBUTES
      end

      def initialize(params)
        set_attributes(params)
        @type = params[:type]
        @source = params[:scm_name]
	@url = params[:source]
      end

      def tohash
        {  :rtype => @type,
          :source => @source,
          :oneclick => nil,
          :url => @url
        }
      end

    end

    class Operations
      include Nilavu::MegamAttributes
      attr_reader :type, :desc, :prop

      ATTRIBUTES = []

      CI = "CI".freeze
      CI_DESCRIPTON = "always up to date code. sweet."

      BIND = "bind".freeze
      BIND_DESCRIPTON = "bind. sweet."
      def initialize(params,type, desc)
        @type = type
        @desc = desc
        #set_attributes(params)
	@prop = prop(params)
      end

      def attributes
        ATTRIBUTES
      end

      def tohash
        {   :operation_type => @type,
          :description => @desc,
          :properties => @prop
        }
      end
	def prop(params)
    op = []
    op << { 'key' => 'type', 'value' => params[:scm_name] }
    op << { 'key' => 'token', 'value' => params[:scmtoken] || '' }
    op << { 'key' => 'username', 'value' => params[:scmowner] || '' }
      op
	end
    end

    class Artifacts
      include Nilavu::MegamAttributes
      ATTRIBUTES = [
        :type,
        :content,
        :requirements]

      def attributes
        ATTRIBUTES
      end<commit_msg>app working<commit_after>require File.expand_path("#{File.dirname(__FILE__)}/megam_attributes")
require File.expand_path("#{File.dirname(__FILE__)}/common_deployable")
require File.expand_path("#{File.dirname(__FILE__)}/outputs")

module Megam
  class Mixins
    class Components
      attr_reader :mixins, :name, :repo, :related_components, :operations, :artifacts, :outputs
      def initialize(params)
        @mixins = CommonDeployable.new(params)
        @name = params[:componentname]
        @outputs = Outputs.new(params)
        @operations = add_operations(params)
        @related_components = add_related_components(params)
        @artifacts = add_artifacts(params)
        @repo = add_repo(params)
      end

      def to_hash
        result = @mixins.to_hash
        result[:name]  = @name if @name
        result[:artifacts]  = @artifacts if @artifacts
        result[:repo]  = @repo if @repo
        result[:operations]  = @operations if @operations
        result[:outputs] = @outputs.to_array  if @outputs
        result[:related_components] = @related_components if @related_components
        result
      end

	def to_a
		[to_hash]
	end

      private

      def add_repo(params)
        Repo.new(params).tohash
      end

      def add_related_components(params)
	related_components = []
        related_components << "#{params[:assemblyname]}.#{params[:domain]}/#{params[:componentname]}" if params.key?(:bind_type)
      end

      def add_operations(params)
        operations = []
        operations.push(create_operation(Operations::CI, Operations::CI_DESCRIPTON,  params)) unless params[:scm_name].strip.empty?
        operations.push(create_operation(Operations::BIND, Operations::BIND_DESCRIPTON, params)) if params.key?(:bind_type)
      end

      def create_operation(type, desc, params)
        Operations.new(params, type, desc).tohash
      end

      def add_artifacts(params)
        Artifacts.new(params).tohash
      end
    end

    class Repo
      include Nilavu::MegamAttributes
      attr_reader :type, :source, :url, :oneclick
      ATTRIBUTES = [
        :type,
        :source,
        :oneclick,
        :url]

      def attributes
        ATTRIBUTES
      end

      def initialize(params)
        set_attributes(params)
        @type = params[:type]
        @source = params[:scm_name]
	@url = params[:source]
	@oneclick = params[:oneclick]
      end

      def tohash
        {  :rtype => @type,
          :source => @source,
          :oneclick => @oneclick,
          :url => @url
        }
      end

    end

    class Operations
      include Nilavu::MegamAttributes
      attr_reader :type, :desc, :prop

      ATTRIBUTES = []

      CI = "CI".freeze
      CI_DESCRIPTON = "always up to date code. sweet."

      BIND = "bind".freeze
      BIND_DESCRIPTON = "bind. sweet."
      def initialize(params,type, desc)
        @type = type
        @desc = desc
        #set_attributes(params)
	@prop = prop(params)
      end

      def attributes
        ATTRIBUTES
      end

      def tohash
        {   :operation_type => @type,
          :description => @desc,
          :properties => @prop
        }
      end
#Key_name mismatch. Key_name is to be changed.
	def prop(params)
    op = []
    op << { 'key' => 'type', 'value' => params[:scm_name] }
    op << { 'key' => 'token', 'value' => params[:scmtoken] || '' }
    op << { 'key' => 'username', 'value' => params[:scmowner] || '' }
      op
	end
    end

    class Artifacts
      include Nilavu::MegamAttributes
      ATTRIBUTES = [
        :type,
        :content,
        :requirements]

      def attributes
        ATTRIBUTES
      end
{'fraction_non_alphanumeric': 0.11610486891385768, 'fraction_numerical': 0.0, 'mean_word_length': 2.3786316776007497, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, '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': '5897790', 'n_tokens_mistral': 2219, 'n_tokens_neox': 2173, 'n_words': 470}