Sha256: 694433a2e4aa780f98a8ce44ee8f6477c09b0f513ae58c7f32fdb39d92a02e59

Contents?: true

Size: 889 Bytes

Versions: 1

Compression:

Stored size: 889 Bytes

Contents

require "date_supercharger/version"
require "date_supercharger/matcher"
require "date_supercharger/method_definer"
require "active_record"

module DateSupercharger
  extend ActiveSupport::Concern

  included do
    def self.method_missing(method_sym, *arguments, &block)
      return super unless descends_from_active_record?
      matcher = Matcher.new(self,method_sym)

      if matcher.match?
        method_definer = MethodDefiner.new(self)
        method_definer.define(attribute: matcher.attribute, suffix: matcher.suffix)
        send(method_sym, *arguments)
      else
        super
      end
    end

    def self.respond_to?(method_sym, include_private = false)
      return super unless descends_from_active_record?
      if Matcher.new(self,method_sym).match?
        true
      else
        super
      end
    end
  end
end
ActiveRecord::Base.send :include, DateSupercharger

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
date_supercharger-0.1.1 lib/date_supercharger.rb