Sha256: fa3fd103f101db62e52de041ed94be98ccd52d8404e01b5f367e05ab1cde92cb

Contents?: true

Size: 580 Bytes

Versions: 1

Compression:

Stored size: 580 Bytes

Contents

module Microscope
  class InstanceMethod < Struct.new(:model, :field)
    def initialize(*args)
      super
      @field_name = field.name
    end

    def cropped_field
      @cropped_field ||= @field_name.gsub(@cropped_field_regex, '')
    end

    # Inject ActiveRecord scopes into a model
    def self.inject_instance_methods(model, fields, _options)
      fields.each do |field|
        scope = "#{field.type.to_s.camelize}InstanceMethod"
        "Microscope::InstanceMethod::#{scope}".constantize.new(model, field).apply if const_defined?(scope)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
microscope-1.0.0 lib/microscope/instance_method.rb