Sha256: a0e12ab63987996a5a6cddaf49ca5e4788f7f8b46460ced8e015bd8e00088b3a

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Riddle
  class Configuration
    class Section
      def self.settings
        []
      end

      def valid?
        true
      end

      private

      def settings_body
        settings.select { |setting|
          !send(setting).nil?
        }.collect { |setting|
          if send(setting) == ""
            conf = "  #{setting} = "
          else
            conf = setting_to_array(setting).collect { |set|
              "  #{setting} = #{rendered_setting set}"
            }
          end
          conf.length == 0 ? nil : conf
        }.flatten.compact
      end

      def setting_to_array(setting)
        value = send(setting)
        case value
        when Array      then value
        when TrueClass  then [1]
        when FalseClass then [0]
        else
          [value]
        end
      end

      def rendered_setting(setting)
        return setting unless setting.is_a?(String)

        index  = 8100
        output = String.new(setting)

        while index < output.length
          output.insert(index, "\\\n")
          index += 8100
        end

        output
      end

      def settings
        self.class.settings
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
riddle-2.4.3 lib/riddle/configuration/section.rb
riddle-2.4.2 lib/riddle/configuration/section.rb
riddle-2.4.1 lib/riddle/configuration/section.rb
riddle-2.4.0 lib/riddle/configuration/section.rb
riddle-2.3.2 lib/riddle/configuration/section.rb
riddle-2.3.1 lib/riddle/configuration/section.rb
riddle-2.3.0 lib/riddle/configuration/section.rb
riddle-2.2.2 lib/riddle/configuration/section.rb
riddle-2.2.1 lib/riddle/configuration/section.rb