Sha256: f2e3370b053cc9989262c08c0b3add873532ec6b8fc12f9dfeb26b20958f764e

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

module Microscope
  class InstanceMethod < Struct.new(:model, :field)
    # 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"

        if Microscope::InstanceMethod.const_defined?(scope)
          "Microscope::InstanceMethod::#{scope}".constantize.new(model, field).apply
        end
      end
    end

    # Convert a past participle to its infinitive form
    def self.past_participle_to_infinitive(participle)
      if Microscope.irregular_verbs.include?(participle)
        Microscope.irregular_verbs[participle]
      elsif participle =~ /ed$/
        participle.sub(/ed$/, '')
      else
        participle
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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