Sha256: 6a3e3fa15a532e37e6a6b463b4c7efa1dc6b1db6316a622ede514b6587415315

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require "season/version"
require "season/configuration"
require "season/legacy"
require "season/scope_builder"
require "season/query_builder"
require "season/instance_method_builder"

module Season

  QUERY_VERBS = ['before', 'after', 'between']

  def self.included(base)
    base.extend(ClassMethods)

    # Define scopes
    sb = ScopeBuilder.new(base)
    base.class_eval do
      base.date_or_time_column_names.each do |column_name|
        QUERY_VERBS.each do |query_verb|
          sb.build(table_name, column_name, query_verb)
        end
      end
    end

    # Define instance methods
    imb = InstanceMethodBuilder.new(base)
    base.class_eval do
      base.date_or_time_column_names.each do |column_name|
        QUERY_VERBS.each do |query_verb|
          imb.build(table_name, column_name, query_verb)
        end
      end
    end
  end

  module ClassMethods
    def date_or_time_column_names
      columns.map { |c| c.name if c.type == :datetime || c.type == :date }.compact
    end
  end

  def self.root
    File.expand_path '../..', __FILE__
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
season-0.3 lib/season.rb