Sha256: 8c68da0e6c1c2f561523b2a82dd5b017e938c26fcd7d06a55943b4b8531f92af

Contents?: true

Size: 584 Bytes

Versions: 1

Compression:

Stored size: 584 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-0.6.2 lib/microscope/instance_method.rb