Sha256: 10faf068688530c88aae7c6fec26a03f7cd0374a39cf1cdb107c5d1f8c6cf201

Contents?: true

Size: 510 Bytes

Versions: 1

Compression:

Stored size: 510 Bytes

Contents

require 'caller_class'

module HasDefaultValue
  module Base
    def self.included(klass)
      klass.extend ClassMethods
    end

    module ClassMethods
      include CallerClass

      def has_default_value(*columns)
        columns.each do |column|
          caller_class.constantize.class_eval <<-RUBY
            def #{column}
              super.present? ? super : I18n.t('activerecord.defaults.#{caller_class.downcase}.#{column}')
            end
          RUBY
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
has_default_value-0.0.1 lib/has_default_value/base.rb