Sha256: ed9d76584fc206ece87c2f231c11c77cc42bc23bead543e466996888c3fcd809

Contents?: true

Size: 942 Bytes

Versions: 3

Compression:

Stored size: 942 Bytes

Contents

# frozen_string_literal: true

module CustomFields
  module Types
    module Tags
      module Field; end

      module Target
        extend ActiveSupport::Concern

        module ClassMethods
          def apply_tags_custom_field(klass, rule)
            klass.field rule['name'], localize: rule['localized'] || false, type: Array

            klass.class_eval do
              define_method("#{rule['name']}=") do |val|
                # FIXME: I would use is_a?(), but it doesn't work in my machine!
                val = val.split(/ *, */) if val.class.to_s == 'String'
                super(val)
              end
            end
          end

          def tags_attribute_get(instance, name)
            default_attribute_get(instance, name)
          end

          def tags_attribute_set(instance, name, attributes)
            default_attribute_set(instance, name, attributes)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
custom_fields-2.14.0.alpha1 lib/custom_fields/types/tags.rb
custom_fields-2.13.1 lib/custom_fields/types/tags.rb
custom_fields-2.13.0 lib/custom_fields/types/tags.rb