<commit_before># vi: ts=2:sts=2:et:sw=2  spell:spelllang=en  
require 'lims-laboratory-app/labels/labellable/create_labellable_shared'
require 'lims-core/actions/action'
module Lims::LaboratoryApp
  module Laboratory
    module CreateLabellableResourceAction
      def self.included(klass) 
        klass.class_eval do
          include Lims::Core::Actions::Action
          include After
          include Lims::LaboratoryApp::Labels::Labellable::CreateLabellableShared
          attribute :labels, Hash, :default => nil
        end
      end

      module After
        def _call_in_session(session)
          # normaly the result should have to keys
          # the uuid one and the model one
          create(session).tap do |result|
            if labels
              uuid = result[:uuid]
              labellable_result = _create(uuid, 'resource', labels, session)
              resource_name = (result.keys - [:uuid]).first
              resource = result[resource_name]
              resource.labellable = labellable_result[:labellable]
            end
          end
        end
      end
    end
  end
end<commit_msg>Bind the resource to the labellable<commit_after># vi: ts=2:sts=2:et:sw=2  spell:spelllang=en  
require 'lims-laboratory-app/labels/labellable/create_labellable_shared'
require 'lims-core/actions/action'
module Lims::LaboratoryApp
  module Laboratory
    module CreateLabellableResourceAction
      def self.included(klass) 
        klass.class_eval do
          include Lims::Core::Actions::Action
          include After
          include Lims::LaboratoryApp::Labels::Labellable::CreateLabellableShared
          attribute :labels, Hash, :default => nil
        end
      end

      module After
        def _call_in_session(session)
          # normaly the result should have to keys
          # the uuid one and the model one
          create(session).tap do |result|
            if labels
              uuid = result[:uuid]
              labellable_result = _create(uuid, 'resource', labels, session)
              resource_name = (result.keys - [:uuid]).first
              resource = result[resource_name]
              session.persistor_for(resource_name).bind(resource, labellable_result[:labellable])
            end
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07932379713914174, 'fraction_numerical': 0.002600780234070221, 'mean_word_length': 2.3160919540229883, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6273678', 'n_tokens_mistral': 650, 'n_tokens_neox': 638, 'n_words': 154}