<commit_before>#EnhancedDateSelect
if defined?(Rails) && defined?(ActionView)
  module ActionView
    module Helpers
      module FormOptionsHelper
        def enhanced_date_select object, method, options = {}, html_options = {}
          InstanceTag.new(object, method, self, options.delete(:object)).to_enhanced_date_select_tag(options, html_options)
        end
      end


      class InstanceTag
        def to_enhanced_date_select_tag  options, html_options
          enhanced_datetime_selector(options, html_options).enhanced_select_date.html_safe
        end

        private
        def enhanced_datetime_selector(options, html_options)
          datetime = options[:value] || value(object) || default_datetime(options)

          @auto_index ||= nil

          options = options.dup
          options[:field_name]           = @method_name
          options[:include_position]     = true
          options[:prefix]             ||= @object_name
          options[:index]                = @auto_index if @auto_index && !options.has_key?(:index)

          EnhancedDateTimeSelector.new(datetime, options, html_options)
        end

      end


      class EnhancedDateTimeSelector < DateTimeSelector

        def enhanced_select_date
          order = date_order.dup

          @options[:discard_hour]     = true
          @options[:discard_minute]   = true
          @options[:discard_second]   = true

          @options[:discard_year]   ||= true unless order.include?(:year)
          @options[:discard_month]  ||= true unless order.include?(:month)
          @options[:discard_day]    ||= true if @options[:discard_month] || !order.include?(:day)

          # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are valid (otherwise it could be 31 and February wouldn't be a valid date)
          if @datetime && @options[:discard_day] && !@options[:discard_month]
            if  @datetime.is_a?(Hash)
              @datetime[:day] = 1
            else
              @datetime = @datetime.change(:day => 1)
            end
          end

          [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) }

          build_selects_from_types(order)
        end

        private
        %w( sec min hour day month year ).each do |method|
          define_method(method) do
            if @datetime
              if  @datetime.kind_of?(Fixnum)
                @datetime
              elsif  @datetime.is_a?(Hash)
                @datetime[method.to_sym]
              else
                @datetime.send(method)
              end
            end
          end
        end



      end

      class FormBuilder
        def enhanced_date_select method, options = {}, html_options = {}
          @template.enhanced_date_select(@object_name, method, objectify_options(options), html_options)
        end
      end<commit_msg>upgdate to work with rails 4<commit_after># #EnhancedDateSelect
if defined?(Rails) && defined?(ActionView)
  module ActionView
    module Helpers
      module FormOptionsHelper
        def enhanced_date_select object, method, options = {}, html_options = {}
          if ( Rails::VERSION::MAJOR.to_i <= 3 )
            @instance_tag =   InstanceTag.new(object, method, self, options.delete(:object))
          else
            @instance_tag = Tags::Base.new(object, method, self, options)
          end
          @instance_tag .to_enhanced_date_select_tag(options, html_options)
        end
      end

      module EnhancedDateSelectTagHelper
        def to_enhanced_date_select_tag options, html_options
          enhanced_datetime_selector(options, html_options).enhanced_select_date.html_safe
        end

        private
        def enhanced_datetime_selector(options, html_options)
          datetime = options[:value] || value(object) || default_datetime(options)

          @auto_index ||= nil

          options = options.dup
          options[:field_name] = @method_name
          options[:include_position] = true
          options[:prefix] ||= @object_name
          options[:index] = @auto_index if @auto_index && !options.has_key?(:index)

          EnhancedDateTimeSelector.new(datetime, options, html_options)
        end

      end
      class InstanceTag
        include EnhancedDateSelectTagHelper

      end

      module Tags
        class Base
          include EnhancedDateSelectTagHelper

        end
      end

      class EnhancedDateTimeSelector < DateTimeSelector

        def enhanced_select_date
          order = date_order.dup

          @options[:discard_hour] = true
          @options[:discard_minute] = true
          @options[:discard_second] = true

          @options[:discard_year] ||= true unless order.include?(:year)
          @options[:discard_month] ||= true unless order.include?(:month)
          @options[:discard_day] ||= true if @options[:discard_month] || !order.include?(:day)

          # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are valid (otherwise it could be 31 and February wouldn't be a valid date)
          if @datetime && @options[:discard_day] && !@options[:discard_month]
            if @datetime.is_a?(Hash)
              @datetime[:day] = 1
            else
              @datetime = @datetime.change(:day => 1)
            end
          end

          [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) }

          build_selects_from_types(order)
        end

        private
        %w( sec min hour day month year ).each do |method|
          define_method(method) do
            if @datetime
              if @datetime.kind_of?(Fixnum)
                @datetime
              elsif @datetime.is_a?(Hash)
                @datetime[method.to_sym]
              else
                @datetime.send(method)
              end
            end
          end
        end



      end

      class FormBuilder
        def enhanced_date_select method, options = {}, html_options = {}
          @template.enhanced_date_select(@object_name, method, objectify_options(options), html_options)
        end
      end
{'fraction_non_alphanumeric': 0.08923927178153446, 'fraction_numerical': 0.0019505851755526658, 'mean_word_length': 2.1424923391215525, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4709964', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1632, 'n_words': 403}