Sha256: 7cb23fa8532340abf3be9f75d38bd8909be43d70cb8237b536e72117c7aba379

Contents?: true

Size: 1.24 KB

Versions: 24

Compression:

Stored size: 1.24 KB

Contents

require 'intercom/generic_handlers/base_handler'

module Intercom
  module GenericHandlers
    module TagFindAll
      module ClassMethods
        def generic_tag_find_all(method_sym, *arguments, &block)

          handler_class = Class.new(GenericHandlers::BaseHandler) do
            def handle
              if method_string.start_with? 'find_all_for_'
                return do_tag_find_all
              else
                raise_no_method_missing_handler
              end
            end

            private

            def do_tag_find_all
              Intercom::Tag.find_all(cleaned_arguments.merge(:taggable_type => Utils.singularize(context)))
            end

            def cleaned_arguments
              cleaned_args = arguments[0]
              cleaned_args[:taggable_id] = cleaned_args.delete(:id) if cleaned_args.has_key?(:id)
              cleaned_args
            end

            def context; method_string.gsub(/^find_all_for_/, ''); end
          end

          handler_class.new(method_sym, arguments, self).handle
        end

      end

      def self.handles_method?(method_sym)
        method_sym.to_s.start_with? 'find_all_for_'
      end

      def self.included(base)
        base.extend(ClassMethods)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
cogniteev-intercom-2.5.4 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.5.4 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.4.4 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.4.3 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.4.2 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.4.1 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.4.0 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.3.0 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.2.4 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.2.3 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.2.2 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.2.1 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.2.0 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.1.6 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.1.5 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.1.4 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.1.3 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.1.2 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.1.1 lib/intercom/generic_handlers/tag_find_all.rb
intercom-2.1.0 lib/intercom/generic_handlers/tag_find_all.rb