<commit_before>module DTK; class ComponentModule
  module DSLMixin
    r8_nested_require('dsl_mixin','external_refs')
    include ExternalRefsMixin

    def install__process_dsl(repo,module_branch,local,opts={})
      parsed = create_needed_objects_and_dsl?(repo,local,opts)
      parsed
    end

    def update_from_initial_create(commit_sha,repo_idh,version,opts={})
      ret = {:dsl_created_info => Hash.new}
      module_branch = get_workspace_module_branch(version)
      pull_was_needed = module_branch.pull_repo_changes?(commit_sha)

      parse_needed = !dsl_parsed?()
      return ret unless pull_was_needed or parse_needed
      repo = repo_idh.create_object()
      deprecate_create_needed_objects_and_dsl?(repo,version,opts)
    end

    def create_new_dsl_version(new_dsl_integer_version,format_type,module_version)
      unless new_dsl_integer_version == 2
        raise Error.new("component_module.create_new_dsl_version only implemented when target version is 2")
      end
      previous_dsl_version = new_dsl_integer_version-1 
      module_branch = get_module_branch_matching_version(module_version)

      #create in-memory dsl object using old version
      component_dsl = ComponentDSL.create_dsl_object(module_branch,previous_dsl_version)
      #create from component_dsl the new version dsl
      dsl_paths_and_content = component_dsl.migrate(module_name(),new_dsl_integer_version,format_type)
      module_branch.serialize_and_save_to_repo(dsl_paths_and_content)
    end

    def pull_from_remote__update_from_dsl(repo, module_and_branch_info,version=nil)
      info = module_and_branch_info #for succinctness
      module_branch_idh = info[:module_branch_idh]
      module_branch = module_branch_idh.create_object().merge(:repo => repo)

      deprecate_create_needed_objects_and_dsl?(repo,version)
    end

    def parse_dsl_and_update_model(impl_obj,module_branch_idh,version=nil,opts={})
      set_dsl_parsed!(false)
      ComponentDSL.parse_and_update_model(self,impl_obj,module_branch_idh,version,opts)
      set_dsl_parsed!(true)
    end

    #TODO: for testing
    def test_generate_dsl()
      module_branch = get_module_branch_matching_version()
      config_agent_type = :puppet
      impl_obj = module_branch.get_implementation()
      parse_impl_to_create_dsl(config_agent_type,impl_obj)
    end
    ### end: for testing

  private
    def create_new_version__type_specific(repo_for_new_branch,new_version,opts={})
      deprecate_create_needed_objects_and_dsl?(repo_for_new_branch,new_version,opts)
    end

    def update_model_from_clone__type_specific?(commit_sha,diffs_summary,module_branch,version,opts={})
      update_model_objs_or_create_dsl?(diffs_summary,module_branch,version,opts)
    end

    def deprecate_create_needed_objects_and_dsl?(repo,version,opts={})
      #TODO: used temporarily until get all callers to use local object
      local = deprecate_ret_local(version)
Log.error_pp(["Using deprecate_create_needed_objects_and_dsl?; local =",local])
      create_needed_objects_and_dsl?(repo,local,opts)
    end
    def deprecate_ret_local(version)
      local_params = ModuleBranch::Location::LocalParams::Server.new(
        :module_type => module_type(),
        :module_name => module_name(),
        :version => version
      )
      local_params.create_local(get_project())
    end
    def create_needed_objects_and_dsl?(repo,local,opts={})
      ret = Hash.new
      module_name = local.module_name
      branch_name = local.branch_name
      version = local.version
      project = local.project
      config_agent_type = config_agent_type_default()
      impl_obj = Implementation.create_workspace_impl?(project.id_handle(),repo,module_name,config_agent_type,branch_name,version)
      impl_obj.create_file_assets_from_dir_els()

      module_and_branch_info = self.class.create_ws_module_and_branch_obj?(project,repo.id_handle(),module_name,version,opts[:ancestor_branch_idh])
      module_branch_idh = module_and_branch_info[:module_branch_idh]
      external_dependencies = matching_branches = nil
      if opts[:process_external_refs]
        module_branch = module_branch_idh.create_object()
        if external_deps = process_external_refs(module_branch,config_agent_type,project,impl_obj)
          if poss_problems = external_deps.possible_problems?()
            ret.merge!(:external_dependencies => poss_problems)
          end<commit_msg>feature_module_location: further pushing local into methods<commit_after>module DTK; class ComponentModule
  module DSLMixin
    r8_nested_require('dsl_mixin','external_refs')
    include ExternalRefsMixin

    def install__process_dsl(repo,module_branch,local,opts={})
      parsed = create_needed_objects_and_dsl?(repo,local,opts)
      parsed
    end

    def update_from_initial_create(commit_sha,repo_idh,version,opts={})
      ret = {:dsl_created_info => Hash.new}
      module_branch = get_workspace_module_branch(version)
      pull_was_needed = module_branch.pull_repo_changes?(commit_sha)

      parse_needed = !dsl_parsed?()
      return ret unless pull_was_needed or parse_needed
      repo = repo_idh.create_object()
      deprecate_create_needed_objects_and_dsl?(repo,version,opts)
    end

    def create_new_dsl_version(new_dsl_integer_version,format_type,module_version)
      unless new_dsl_integer_version == 2
        raise Error.new("component_module.create_new_dsl_version only implemented when target version is 2")
      end
      previous_dsl_version = new_dsl_integer_version-1 
      module_branch = get_module_branch_matching_version(module_version)

      #create in-memory dsl object using old version
      component_dsl = ComponentDSL.create_dsl_object(module_branch,previous_dsl_version)
      #create from component_dsl the new version dsl
      dsl_paths_and_content = component_dsl.migrate(module_name(),new_dsl_integer_version,format_type)
      module_branch.serialize_and_save_to_repo(dsl_paths_and_content)
    end

    def pull_from_remote__update_from_dsl(repo, module_and_branch_info,version=nil)
      info = module_and_branch_info #for succinctness
      module_branch_idh = info[:module_branch_idh]
      module_branch = module_branch_idh.create_object().merge(:repo => repo)

      deprecate_create_needed_objects_and_dsl?(repo,version)
    end

    def parse_dsl_and_update_model(impl_obj,module_branch_idh,version=nil,opts={})
      set_dsl_parsed!(false)
      ComponentDSL.parse_and_update_model(self,impl_obj,module_branch_idh,version,opts)
      set_dsl_parsed!(true)
    end

    #TODO: for testing
    def test_generate_dsl()
      module_branch = get_module_branch_matching_version()
      config_agent_type = :puppet
      impl_obj = module_branch.get_implementation()
      parse_impl_to_create_dsl(config_agent_type,impl_obj)
    end
    ### end: for testing

  private
    def create_new_version__type_specific(repo_for_new_branch,new_version,opts={})
      deprecate_create_needed_objects_and_dsl?(repo_for_new_branch,new_version,opts)
    end

    def update_model_from_clone__type_specific?(commit_sha,diffs_summary,module_branch,version,opts={})
      update_model_objs_or_create_dsl?(diffs_summary,module_branch,version,opts)
    end

    def deprecate_create_needed_objects_and_dsl?(repo,version,opts={})
      #TODO: used temporarily until get all callers to use local object
      local = deprecate_ret_local(version)
Log.error_pp(["Using deprecate_create_needed_objects_and_dsl?; local =",local])
      create_needed_objects_and_dsl?(repo,local,opts)
    end
    def deprecate_ret_local(version)
      local_params = ModuleBranch::Location::LocalParams::Server.new(
        :module_type => module_type(),
        :module_name => module_name(),
        :version => version
      )
      local_params.create_local(get_project())
    end
    def create_needed_objects_and_dsl?(repo,local,opts={})
      ret = Hash.new
      module_name = local.module_name
      branch_name = local.branch_name
      version = local.version
      project = local.project
      config_agent_type = config_agent_type_default()
      impl_obj = Implementation.create_workspace_impl?(project.id_handle(),repo,module_name,config_agent_type,branch_name,version)
      impl_obj.create_file_assets_from_dir_els()

      module_and_branch_info = self.class.create_module_and_branch_obj?(project,repo.id_handle(),local,opts[:ancestor_branch_idh])
      module_branch_idh = module_and_branch_info[:module_branch_idh]
      external_dependencies = matching_branches = nil
      if opts[:process_external_refs]
        module_branch = module_branch_idh.create_object()
        if external_deps = process_external_refs(module_branch,config_agent_type,project,impl_obj)
          if poss_problems = external_deps.possible_problems?()
            ret.merge!(:external_dependencies => poss_problems)
          end
{'fraction_non_alphanumeric': 0.07628935786028665, 'fraction_numerical': 0.000902832637399842, 'mean_word_length': 4.861111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4221642', 'n_tokens_mistral': 2893, 'n_tokens_neox': 2838, 'n_words': 384}