Sha256: 5124b62cd1c9ffd101b495215d9f9d10fea9a1073cc18252d3d8829efd0e02a5

Contents?: true

Size: 877 Bytes

Versions: 27

Compression:

Stored size: 877 Bytes

Contents

module ActiveTools
  module ActiveRecord
    module FilterAssign
      extend ::ActiveSupport::Concern
      
      included do
      end
      
      module ClassMethods
        def filter_assign(*args)
          options = args.extract_options!
          args.each do |attribute|
            define_method "#{attribute}=" do |value|
              if (options[:if].nil? || (options[:if].is_a?(Proc) && options[:if].call(value) == true)) && (options[:unless].nil? || (options[:unless].is_a?(Proc) && options[:unless].call(value) == false))
                if options.has_key?(:force_value)
                  super(options[:force_value])
                end
              else
                super(value)
              end
            end
          end
        end
      end
      
    end
  end
  
  module OnLoadActiveRecord
    include ActiveRecord::FilterAssign
  end
  
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
active_tools-0.1.0 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.52 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.51 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.50 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.42 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.41 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.40 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.39 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.38 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.37 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.36 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.35 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.34 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.33 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.32 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.31 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.30 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.29 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.28 lib/active_tools/active_record/filter_assign.rb
active_tools-0.0.27 lib/active_tools/active_record/filter_assign.rb