rubocop:disable Metrics/AbcSize
506607
def calculate_pointsize(text, size_range: 28...128)
      draw = Magick::Draw.new
      draw.font = File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'fonts', 'Impact.ttf')
      draw.font_weight = Magick::BoldWeight

      size = size_range.detect(-> { size_range.last }) do |pointsize|
        draw.pointsize = pointsize + 1
        current_stroke = pointsize / 30.0

        metrics = draw.get_multiline_type_metrics(text)

        metrics.width + current_stroke > @canvas.columns - 20 || metrics.height + current_stroke > (@canvas.rows / 2) - 20
      end
      [draw, size]
    end
182789
def [](key, src = name.to_sym)
      attr =
        if count_index[key].equal?(1)
          name_index[key]
        else
          source_index[src][key]
        end

      unless attr
        raise(KeyError, "#{key.inspect} attribute doesn't exist in #{src} schema")
      end

      attr
    end
767282
def to_h
      @size_dep.depend

      if @attributes.nil?
        nil
      else
        hash = {}
        @attributes.each_pair do |key, value|
          hash[key] = deep_unwrap(value)
        end
        hash
      end
    end
1167072
def load
      @comments = self.build
      max_size = @comments.values.max_by(&:size).try(:size)
      
      load_comments(Rails.root.join('app', 'controllers').to_s, max_size) do |file, line|
        if get_finder === line
          found_method = $1
          
          comments = build_comments(found_method, line.chomp.match(/^(\s*)[^\s]*/)[1])
          file.write(comments.join) unless file.trailing?(comments)
          
          @comments.delete(found_method)
          get_finder(true)
        end
        
        file.write(line)
      end
    end
456214
def standard?
      self.syntax = :invalid
      self.valid_size? or return false
      self.valid_encoding? or return false
      if self.local =~ STANDARD_LOCAL_REGEX
        self.syntax = :standard
        true
      else
        false
      end
    end
521963
def execute!
      begin
        options   = Options.new(argv)

        generator = ErbGenerator.new(Data.new(options.data_sources))
        generator.compile(options.source, options.destination)

        exitstatus = 0
      rescue Interrupt
        Filegen::Ui.warning 'You told me to stop command execution.'
        exitstatus = 2
      rescue Exceptions::ErbTemplateHasSyntaxErrors => e
        Filegen::Ui.error "Syntax error in ERB-Template: \n" + e.message
        exitstatus = 3
      rescue Exceptions::YamlFileNotFound => e
        Filegen::Ui.error "Yaml-file \"#{JSON.parse(e.message)['file']}\" not found."
        exitstatus = 4
      rescue StandardError => e
        Filegen::Ui.error "#{e.class} - #{e.message}"
        exitstatus = 99
      end

      @kernel.exit(exitstatus)
    end
584210
def index
      if defined?(ActiveRecord)
        @ar_error_messages = params[:app] ? RailsExceptionHandler::ActiveRecord::ErrorMessage.where(app_name: params[:app]).order('created_at DESC') : RailsExceptionHandler::ActiveRecord::ErrorMessage.order('created_at DESC')
      end
      if defined?(Mongoid)
        @mg_error_messages = params[:app] ? RailsExceptionHandler::Mongoid::ErrorMessage.where(app_name: params[:app]).order(created_at: 'desc') : RailsExceptionHandler::Mongoid::ErrorMessage.order_by(created_at: 'desc')
      end
      if defined?(WillPaginate)
        @ar_error_messages = @ar_error_messages.paginate(page: params[:page] || 1, per_page: params[:per_page] || 100)
      elsif defined?(Kaminari)
        @ar_error_messages = @ar_error_messages.page(params[:page] || 1).per(params[:per_page] || 100)
      end

      respond_to do |format|
        format.html # index.html.erb
        format.json {
          if @ar_error_messages.present? && @mg_error_messages.present?
            json = {active_record: @ar_error_messages, mongoid: @mg_error_messages}
          elsif @ar_error_messages.present? && @mg_error_messages.blank?
            json = @ar_error_messages
          elsif @ar_error_messages.blank? && @mg_error_messages.present?
            json = @mg_error_messages
          end
          render json: json
        }
      end
    end
644785
def index
      @project = Project.find params[:project_id]
      @apis = @project.apis.page(params[:page]).per(RailsApiDoc::Api::DEFAULT_PAGE_SIZE)
  
      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @apis }
      end
    end
584437
def to_s
      msg = super
      @file = nil if (@file.is_a?(String) && @file.empty?)
      msg += Puppet::Util::Errors.error_location_with_space(@file, @line, @pos)
      msg
    end
1299527
def initialize_metal
      Rails::Rack::Metal.requested_metals = configuration.metals
      Rails::Rack::Metal.metal_paths = ["#{TRUSTY_CMS_ROOT}/app/metal"] # reset Rails default to TRUSTY_CMS_ROOT
      Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
      Rails::Rack::Metal.metal_paths += extension_loader.paths(:metal)
      Rails::Rack::Metal.metal_paths.uniq!

      configuration.middleware.insert_before(
        :"ActionController::ParamsParser",
        Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?)
    end
246061
def formatted_size
      @formats.rcompact!
      sz = size
      fs = @formats.size
      fs > sz ? fs : sz
    end
929988
def run
      unless opts[:action]
        usage
        exit 255
      end

      @config = {}

      if opts[:config]
        @config = YAML.load_file(opts[:config])
        substitute_relative_paths!(@config, File.dirname(opts[:config]))
        load_plugins(@config["plugins"]) if @config.key?("plugins")
      end

      @config[:options] = {}
      opts.each do |k, v|
        if v.is_a?(Hash)
          @config[k.to_s] ||= {}
          v.each do |v_key, v_val|
            @config[k.to_s][v_key.to_s] = v_val
            @config[k.to_s].delete(v_key.to_s) if v_val.nil?
          end
        else
          @config[:options][k] = v
        end
      end

      return handle_action_bulk if opts[:action] == "bulk"
      return handle_action_facts if opts[:action] == "facts"
      return handle_action_bulk if opts[:action] == "reindex"

      usage
      exit 255
    end
1067352
def limited_files_of(parent)
      ::Dir["#{parent}/*"].each do |item|
        if ::File.file?(item)
          if ::File.stat(item).size <= JAILED_FILE_SIZE_CONSTRAINT
            yield item
          else
            if ::File.basename(item) == RUBY_METADATA
              raise MetadataError,
                    'Metadata source file' +
                    " #{relative_to_repo_dir(item).inspect}" +
                    ' in repository exceeded size constraint of' +
                    " #{JAILED_FILE_SIZE_CONSTRAINT / 1024} KB"
            else
              message = 'Ignored a repository file during metadata' +
                        ' generation due to exceeding size constraint of' +
                        " #{JAILED_FILE_SIZE_CONSTRAINT / 1024} KB:" +
                        " #{relative_to_repo_dir(item).inspect}"
              @logger.info(message)
            end
          end
        end
      end
    end
69807
def load_config
      @log.debug "loading validator-specific configuration"
      config = Autosign::Config.new

      if config.settings.to_hash[self.name].nil?
        @log.warn "Unable to load validator-specific configuration"
        @log.warn "Cannot load configuration section named '#{self.name}'"
        return {}
      else
        @log.debug "Set validator-specific settings from config file: " + config.settings.to_hash[self.name].to_s
        return config.settings.to_hash[self.name]
      end
    end
664767
def parse_gem(init_lib)
      # puts "Processing: #{init_lib}"
      # don't ask
      init_path = init_lib

      init_file = File.read(init_lib)
      current_file = ""

      init_file.each_line do |line|
        if line.strip =~ /^require/
          parser = RubyParser.new
          sexp = parser.parse(line)
          call = sexp[2]

          unless call == :require
            # WEIRD SHIT IS HAPPENING
            current_file += line
            next
          end

          require_type = sexp[3][1][0]
          library = sexp[3][1][1]
          #p library

          if require_type == :str && library.match(@gem_name)
            # fold in
            full_rb_path = File.join([@lib_folder, "#{library}.rb"])
            unless @require_libs.include?(full_rb_path)
              file_index = @require_libs.index(init_lib)
              insert_index = file_index
              @require_libs.insert insert_index, full_rb_path
              parse_gem(full_rb_path)
            end
          else
            current_file += "# FIXME: #require is not supported in RubyMotion\n"
            current_file += "# #{line}"
            next
          end
          # comment it out
          current_file += "# #{line}"
          next
        elsif line.strip =~ /^autoload/
          # same as require
          parser = RubyParser.new
          sexp = parser.parse(line)
          call = sexp[2]

          unless call == :autoload
            # WEIRD SHIT IS HAPPENING
            current_file += line
            next
          end

          require_type = sexp[3][2][0]
          library = sexp[3][2][1]

          full_rb_path = File.join([@lib_folder, "#{library}.rb"])
          unless @require_libs.include?(full_rb_path)
            file_index = @require_libs.index(init_lib)
            insert_index = file_index
            @require_libs.insert insert_index, full_rb_path
            parse_gem(full_rb_path)
          end
          # comment it out
          current_file += "# #{line}"
          next

        
        elsif line.strip =~ /^eval/
            # reprint as a block
            # parser = RubyParser.new
            # sexp = parser.parse(line)
            # code_str = sexp[3][1][1]
            # new_eval = "eval do\n  #{code_str}\nend\n"
            # current_file += "#{new_eval}"
            # next

            # produce a fixme

            current_file += "# FIXME: Cannot eval strings in RubyMotion. \n"
            current_file += "# Rewrite to use a block.. inbuilt hack will run \n"
            current_file += "# Change this: \n"
            current_file += "# eval %Q{ \n" 
            current_file += '# def #{c}(string = nil) ' + "\n"
            current_file += "# To this \n"
            current_file += "# eval do \n"
            current_file += "# define_method(c) do |string| \n"
            current_file += "#{line}"
            next
        elsif line.strip =~ /^binding/
            current_file += "# FIXME: binding is not supported in RubyMotion.\n"
            current_file += "#{line}"
            next
        end

        # dont intefere
        current_file += line
      end

      # replace file
      File.open(init_lib, 'w') {|f| f.write(current_file) } #unless TEST_MODE

    end
366171
def grow
      @lock.synchronize do
        prune
        logger.debug { "jobs: #{num_jobs}; busy: #{num_working}; idle: #{num_idle}" }
        if @size == 0 || (@size < @max_size && num_jobs > 0 && num_jobs > num_idle) then
          space = @max_size-@size
          jobs = num_jobs-num_idle
          needed = space < jobs ? space : jobs
          needed = 1 if needed <= 0
          expand(needed)
        else
          logger.debug "NOT growing the pool!"
        end
      end

      nil
    end
399791
def load(attributes)
      raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
      @prefix_options, attributes = split_options(attributes)
      attributes.each do |key, value|
        @attributes[key.to_s] = typecast_attribute_value(key, value)
      end
      self
    end