Sha256: 5d8d01a6c47533ac88a9bf3dc11b3e330ffb159dcf73b052c9013603795aee06

Contents?: true

Size: 737 Bytes

Versions: 17

Compression:

Stored size: 737 Bytes

Contents

require 'active_record'

module EacRailsUtils
  module Patches
    module ModelAttributeRequired
      def self.included(base)
        base.extend ClassMethods
        base.include InstanceMethods
      end

      module ClassMethods
        def column_required?(column)
          m = new
          m.validate
          m.errors.key?(column.to_sym)
        end
      end

      module InstanceMethods
        def attribute_required?(column)
          self.class.column_required?(column)
        end
      end
    end
  end
end

[::ActiveRecord::Base, ::ActiveModel::Model].each do |c|
  next if c.included_modules.include? ::EacRailsUtils::Patches::ModelAttributeRequired
  c.include ::EacRailsUtils::Patches::ModelAttributeRequired
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
eac_rails_utils-0.8.0 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.7.1 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.7.0 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.6.0 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.5.0 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.4.0 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.3.0 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.2.2 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.2.1 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.2.0 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.1.15 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.1.14 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.1.13 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.1.12 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.1.11 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.1.10 lib/eac_rails_utils/patches/model_attribute_required.rb
eac_rails_utils-0.0.1 lib/eac_rails_utils/patches/model_attribute_required.rb