← back to Flytedesk__pack_api

Function bodies 314 total

All specs Real LLM only Function bodies
PackAPI::FrozenEmpty class · ruby · L1-L4 (4 LOC)
lib/pack_api/frozen_empty.rb
class PackAPI::FrozenEmpty
  ARRAY = [].freeze
  HASH = {}.freeze
end
InternalError class · ruby · L6-L24 (19 LOC)
lib/pack_api/internal_error.rb
  class InternalError < StandardError
    attr_reader :object, :options

    def initialize(msg = nil, object: nil, options: {})
      super(msg)
      @object = object
      @options = options
    end

    def message
      to_s
    end

    def to_s
      return super unless object.present?

      "#{super} - #{object.inspect}"
    end
  end
initialize method · ruby · L9-L13 (5 LOC)
lib/pack_api/internal_error.rb
    def initialize(msg = nil, object: nil, options: {})
      super(msg)
      @object = object
      @options = options
    end
message method · ruby · L15-L17 (3 LOC)
lib/pack_api/internal_error.rb
    def message
      to_s
    end
to_s method · ruby · L19-L23 (5 LOC)
lib/pack_api/internal_error.rb
    def to_s
      return super unless object.present?

      "#{super} - #{object.inspect}"
    end
AbstractTransformer class · ruby · L4-L42 (39 LOC)
lib/pack_api/mapping/abstract_transformer.rb
  class AbstractTransformer
    attr_accessor :mappings, :api_type, :model_type, :data_source
    attr_reader :options

    def initialize(config)
      @mappings = config[:mappings]
      @api_type = config[:api_type]
      @model_type = config[:model_type]
      @transform_value = config[:transform_value]
      @options = PackAPI::FrozenEmpty::HASH
    end

    ###
    # @abstract
    def execute
      raise NotImplementedError
    end

    def options=(value)
      @options = value.presence || PackAPI::FrozenEmpty::HASH
    end

    protected

    def transform_value(api_attribute, value)
      @transform_value.call(api_attribute, value)
    end

    def model_attribute(api_attribute)
      # support _destroy and other special attributes used by Rails
      return api_attribute if api_attribute.start_with?('_')

      # prevent api_attributes from being used unless they are in the public type definition
      unless mappings.key?(api_attribute)
        raise PackAPI::InternalError.n
initialize method · ruby · L8-L14 (7 LOC)
lib/pack_api/mapping/abstract_transformer.rb
    def initialize(config)
      @mappings = config[:mappings]
      @api_type = config[:api_type]
      @model_type = config[:model_type]
      @transform_value = config[:transform_value]
      @options = PackAPI::FrozenEmpty::HASH
    end
Citation: Repobility (2026). State of AI-Generated Code. https://repobility.com/research/
execute method · ruby · L18-L20 (3 LOC)
lib/pack_api/mapping/abstract_transformer.rb
    def execute
      raise NotImplementedError
    end
options= method · ruby · L22-L24 (3 LOC)
lib/pack_api/mapping/abstract_transformer.rb
    def options=(value)
      @options = value.presence || PackAPI::FrozenEmpty::HASH
    end
transform_value method · ruby · L28-L30 (3 LOC)
lib/pack_api/mapping/abstract_transformer.rb
    def transform_value(api_attribute, value)
      @transform_value.call(api_attribute, value)
    end
model_attribute method · ruby · L32-L39 (8 LOC)
lib/pack_api/mapping/abstract_transformer.rb
    def model_attribute(api_attribute)
      # support _destroy and other special attributes used by Rails
      return api_attribute if api_attribute.start_with?('_')

      # prevent api_attributes from being used unless they are in the public type definition
      unless mappings.key?(api_attribute)
        raise PackAPI::InternalError.new("unknown attribute '#{api_attribute}' for #{@model_type.name}.")
      end
api_attribute_names method · ruby · L44-L46 (3 LOC)
lib/pack_api/mapping/abstract_transformer.rb
    def api_attribute_names
      api_type.attribute_names
    end
APIToModelAttributesTransformer class · ruby · L7-L18 (12 LOC)
lib/pack_api/mapping/api_to_model_attributes_transformer.rb
  class APIToModelAttributesTransformer < AbstractTransformer
    def execute
      result = {}
      attribute_names = NormalizedAPIAttribute.new(api_attribute_names)
      data_source.each do |api_attribute, api_value|
        normalized_api_attribute = attribute_names.normalize(api_attribute)
        model_attribute = model_attribute(normalized_api_attribute)
        model_value = transform_value(normalized_api_attribute, api_value)
        result[model_attribute] = model_value
      end
      result
    end
execute method · ruby · L8-L16 (9 LOC)
lib/pack_api/mapping/api_to_model_attributes_transformer.rb
    def execute
      result = {}
      attribute_names = NormalizedAPIAttribute.new(api_attribute_names)
      data_source.each do |api_attribute, api_value|
        normalized_api_attribute = attribute_names.normalize(api_attribute)
        model_attribute = model_attribute(normalized_api_attribute)
        model_value = transform_value(normalized_api_attribute, api_value)
        result[model_attribute] = model_value
      end
AttributeHashTransformer class · ruby · L11-L31 (21 LOC)
lib/pack_api/mapping/attribute_hash_transformer.rb
  class AttributeHashTransformer < AbstractTransformer
    def execute
      options.fetch(:contains_model_attributes, true) ?
        model_attributes_to_api_attributes :
        api_attributes_to_model_attributes
    end

    protected

    def api_attributes_to_model_attributes
      attribute_names = NormalizedAPIAttribute.new(api_attribute_names)
      result = {}
      data_source.each_key do |api_attribute|
        normalized_api_attribute = attribute_names.normalize(api_attribute)
        next unless mappings.key?(normalized_api_attribute)

        model_attribute = model_attribute(normalized_api_attribute)
        result[model_attribute] = data_source[api_attribute]
      end
      result
    end
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
execute method · ruby · L12-L16 (5 LOC)
lib/pack_api/mapping/attribute_hash_transformer.rb
    def execute
      options.fetch(:contains_model_attributes, true) ?
        model_attributes_to_api_attributes :
        api_attributes_to_model_attributes
    end
api_attributes_to_model_attributes method · ruby · L20-L29 (10 LOC)
lib/pack_api/mapping/attribute_hash_transformer.rb
    def api_attributes_to_model_attributes
      attribute_names = NormalizedAPIAttribute.new(api_attribute_names)
      result = {}
      data_source.each_key do |api_attribute|
        normalized_api_attribute = attribute_names.normalize(api_attribute)
        next unless mappings.key?(normalized_api_attribute)

        model_attribute = model_attribute(normalized_api_attribute)
        result[model_attribute] = data_source[api_attribute]
      end
model_attributes_to_api_attributes method · ruby · L33-L41 (9 LOC)
lib/pack_api/mapping/attribute_hash_transformer.rb
    def model_attributes_to_api_attributes
      reversed_mappings = mappings.invert
      result = {}
      data_source.each_key do |model_attribute|
        next unless reversed_mappings.key?(model_attribute)

        api_attribute = reversed_mappings[model_attribute]
        result[api_attribute] = data_source[model_attribute]
      end
AttributeMap class · ruby · L28-L44 (17 LOC)
lib/pack_api/mapping/attribute_map.rb
  class AttributeMap
    attr_reader :config, :options

    class << self
      def map(source_attr, to: nil, from_api_attribute: nil, from_model_attribute: nil, readonly: nil, transform_nested_attributes_with: nil)
        @mappings ||= {}
        @from_api_attributes ||= {}
        @from_model_attributes ||= {}
        @transform_nested_attributes_with ||= {}
        @mappings[source_attr] = to || source_attr
        @from_model_attributes[source_attr] = from_model_attribute if from_model_attribute.present?
        @from_api_attributes[source_attr] = from_api_attribute if from_api_attribute.present?
        @transform_nested_attributes_with[source_attr] = transform_nested_attributes_with if transform_nested_attributes_with.present?
        if readonly
          @from_api_attributes[source_attr] = ->(*) { raise PackAPI::InternalError, "Unable to modify read-only attribute '#{source_attr}'" }
        end
      end
map method · ruby · L32-L43 (12 LOC)
lib/pack_api/mapping/attribute_map.rb
      def map(source_attr, to: nil, from_api_attribute: nil, from_model_attribute: nil, readonly: nil, transform_nested_attributes_with: nil)
        @mappings ||= {}
        @from_api_attributes ||= {}
        @from_model_attributes ||= {}
        @transform_nested_attributes_with ||= {}
        @mappings[source_attr] = to || source_attr
        @from_model_attributes[source_attr] = from_model_attribute if from_model_attribute.present?
        @from_api_attributes[source_attr] = from_api_attribute if from_api_attribute.present?
        @transform_nested_attributes_with[source_attr] = transform_nested_attributes_with if transform_nested_attributes_with.present?
        if readonly
          @from_api_attributes[source_attr] = ->(*) { raise PackAPI::InternalError, "Unable to modify read-only attribute '#{source_attr}'" }
        end
api_type method · ruby · L46-L50 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
      def api_type(api_type = nil)
        return @api_type unless api_type

        @api_type = api_type
      end
model_type method · ruby · L52-L56 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
      def model_type(model_type = nil)
        return @model_type unless model_type

        @model_type = model_type
      end
config method · ruby · L58-L67 (10 LOC)
lib/pack_api/mapping/attribute_map.rb
      def config
        {
          mappings: @mappings,
          from_api_attributes: @from_api_attributes,
          from_model_attributes: @from_model_attributes,
          transform_nested_attributes_with: @transform_nested_attributes_with,
          api_type: @api_type,
          model_type: @model_type
        }
      end
Same scanner, your repo: https://repobility.com — Repobility
model_attribute_keys function · ruby · L70-L74 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
    def self.model_attribute_keys(hash)
      options = { contains_model_attributes: false,
                  transformer_type_for_source: AttributeHashTransformer.name }
      new(hash.symbolize_keys, options).attributes
    end
api_attribute_keys function · ruby · L76-L80 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
    def self.api_attribute_keys(hash)
      options = { contains_model_attributes: true,
                  transformer_type_for_source: AttributeHashTransformer.name }
      new(hash.symbolize_keys, options).attributes
    end
initialize function · ruby · L85-L91 (7 LOC)
lib/pack_api/mapping/attribute_map.rb
    def initialize(data_source = nil, options = nil)
      @options = DEFAULT_OPTIONS
      @config = self.class.config

      self.options = options
      self.data_source = data_source
    end
from_model_attributes function · ruby · L93-L96 (4 LOC)
lib/pack_api/mapping/attribute_map.rb
    def from_model_attributes
      @from_model_attributes ||= config[:from_model_attributes].transform_values do |proc_or_method_name|
        ValueTransformationChain.new([ValueTransformation.new(self.class, proc_or_method_name, options)])
      end
from_api_attributes function · ruby · L99-L104 (6 LOC)
lib/pack_api/mapping/attribute_map.rb
    def from_api_attributes
      return @from_api_attributes if defined?(@from_api_attributes)

      @from_api_attributes = config[:from_api_attributes].transform_values do |proc_or_method_name|
        ValueTransformationChain.new([ValueTransformation.new(self.class, proc_or_method_name, options)])
      end
data_source= function · ruby · L116-L120 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
    def data_source=(data_source)
      transformer_type = transformer_type_for_source(data_source)
      unless @transformer.is_a?(transformer_type)
        @transformer = transformer_type.new(config_for_adapter_type(transformer_type))
      end
data_source function · ruby · L125-L127 (3 LOC)
lib/pack_api/mapping/attribute_map.rb
    def data_source
      @transformer&.data_source
    end
options= function · ruby · L129-L138 (10 LOC)
lib/pack_api/mapping/attribute_map.rb
    def options=(new_options)
      return if new_options == @provided_options

      @provided_options = new_options
      @options = @provided_options ?
                   DEFAULT_OPTIONS.merge(@provided_options) :
                   DEFAULT_OPTIONS
      from_model_attributes.each_value { |transformation| transformation.kwargs = options }
      @transformer&.options = options
    end
All rows scored by the Repobility analyzer (https://repobility.com)
register_transformation_from_model_attribute function · ruby · L140-L144 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
    def register_transformation_from_model_attribute(source_attr, proc_or_method_name)
      from_model_attributes[source_attr] ||= ValueTransformationChain.new([])
      transformation = ValueTransformation.new(self.class, proc_or_method_name, options)
      from_model_attributes[source_attr].transformations << transformation
    end
attributes function · ruby · L146-L148 (3 LOC)
lib/pack_api/mapping/attribute_map.rb
    def attributes
      @transformer.execute
    end
api_type function · ruby · L150-L152 (3 LOC)
lib/pack_api/mapping/attribute_map.rb
    def api_type
      self.class.api_type
    end
model_type function · ruby · L154-L156 (3 LOC)
lib/pack_api/mapping/attribute_map.rb
    def model_type
      self.class.model_type
    end
convert_nested_attribute function · ruby · L160-L166 (7 LOC)
lib/pack_api/mapping/attribute_map.rb
    def convert_nested_attribute(parent_attribute_value, attribute_map_class:)
      attribute_map = attribute_map_class.new
      if parent_attribute_value.is_a?(Array)
        parent_attribute_value.map do |nested_attributes|
          attribute_map.data_source = nested_attributes
          attribute_map.attributes
        end
transformer_type_for_source function · ruby · L173-L186 (14 LOC)
lib/pack_api/mapping/attribute_map.rb
    def transformer_type_for_source(source)
      if options.key?(:transformer_type_for_source)
        options[:transformer_type_for_source].constantize
      elsif source.nil?
        NullTransformer
      elsif source.is_a?(Hash)
        APIToModelAttributesTransformer
      elsif source.is_a?(ActiveModel::Errors)
        ErrorHashToAPIAttributesTransformer
      elsif source.is_a?(ActiveModel::AttributeAssignment)
        ModelToAPIAttributesTransformer
      else
        raise "Unknown source #{source}"
      end
config_for_adapter_type function · ruby · L189-L198 (10 LOC)
lib/pack_api/mapping/attribute_map.rb
    def config_for_adapter_type(adapter_type)
      if [ErrorHashToAPIAttributesTransformer, ModelToAPIAttributesTransformer].include?(adapter_type)
        transform_value = method(:transform_value_for_api)
        config.merge(transform_value:)
      elsif adapter_type == APIToModelAttributesTransformer
        transform_value = method(:transform_value_for_model)
        config.merge(transform_value:)
      else
        config
      end
transform_value_for_api function · ruby · L201-L205 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
    def transform_value_for_api(api_attribute, model_value)
      from_model_attributes.key?(api_attribute) ?
        from_model_attributes[api_attribute].call(self, model_value) :
        model_value
    end
Citation: Repobility (2026). State of AI-Generated Code. https://repobility.com/research/
transform_value_for_model function · ruby · L207-L211 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
    def transform_value_for_model(api_attribute, api_value)
      from_api_attributes.key?(api_attribute) ?
        from_api_attributes[api_attribute].call(self, api_value) :
        api_value
    end
ValueTransformation class · ruby · L213-L223 (11 LOC)
lib/pack_api/mapping/attribute_map.rb
    class ValueTransformation
      attr_reader :proc, :instance_method

      def initialize(klass, proc_or_method_name, kwargs = nil)
        if proc_or_method_name.is_a?(Proc)
          @proc = proc_or_method_name
        else
          @instance_method = klass.instance_method(proc_or_method_name)
        end
        self.kwargs = kwargs
      end
initialize method · ruby · L216-L221 (6 LOC)
lib/pack_api/mapping/attribute_map.rb
      def initialize(klass, proc_or_method_name, kwargs = nil)
        if proc_or_method_name.is_a?(Proc)
          @proc = proc_or_method_name
        else
          @instance_method = klass.instance_method(proc_or_method_name)
        end
call function · ruby · L225-L234 (10 LOC)
lib/pack_api/mapping/attribute_map.rb
      def call(attribute_map, attribute_value)
        if @kwargs
          proc ?
            attribute_map.instance_exec(attribute_value, **@kwargs, &proc) :
            attribute_map.send(instance_method.name, attribute_value, **@kwargs)
        else
          proc ?
            attribute_map.instance_exec(attribute_value, &proc) :
            attribute_map.send(instance_method.name, attribute_value)
        end
kwargs= function · ruby · L237-L241 (5 LOC)
lib/pack_api/mapping/attribute_map.rb
      def kwargs=(new_kwargs)
        @kwargs = new_kwargs == DEFAULT_OPTIONS || new_kwargs.blank? ?
                    nil :
                  supported_kwargs(new_kwargs)
      end
supported_kwargs function · ruby · L245-L252 (8 LOC)
lib/pack_api/mapping/attribute_map.rb
      def supported_kwargs(kwargs)
        return if parameters.empty?

        overlap = parameters.any? { |p| kwargs.key?(p) }
        return unless overlap

        kwargs.slice(*parameters)
      end
parameters function · ruby · L254-L256 (3 LOC)
lib/pack_api/mapping/attribute_map.rb
      def parameters
        @parameters ||= (proc || instance_method).parameters.map(&:last)
      end
ValueTransformationChain class · ruby · L259-L273 (15 LOC)
lib/pack_api/mapping/attribute_map.rb
    class ValueTransformationChain
      attr_reader :transformations
      def initialize(transformations)
        @transformations = transformations
      end

      def kwargs=(new_kwargs)
        transformations.each { it.kwargs = new_kwargs }
      end

      def call(attribute_map, attribute_value)
        transformations.reduce(attribute_value) do |prev_result, next_transformation|
          next_transformation.call(attribute_map, prev_result)
        end
      end
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
initialize method · ruby · L261-L263 (3 LOC)
lib/pack_api/mapping/attribute_map.rb
      def initialize(transformations)
        @transformations = transformations
      end
kwargs= method · ruby · L265-L267 (3 LOC)
lib/pack_api/mapping/attribute_map.rb
      def kwargs=(new_kwargs)
        transformations.each { it.kwargs = new_kwargs }
      end
call method · ruby · L269-L272 (4 LOC)
lib/pack_api/mapping/attribute_map.rb
      def call(attribute_map, attribute_value)
        transformations.reduce(attribute_value) do |prev_result, next_transformation|
          next_transformation.call(attribute_map, prev_result)
        end
page 1 / 7next ›