rubocop:disable MethodLength
 rubocop:disable AbcSize
423332
def read_loop
      loop do
        unless @options.fetch(:device)
          sleep 0.1
          next
        end
        begin
          raw_data, = raw_socket.recvfrom(8192)
          udp = Pio::Udp.read(raw_data)
          next if @stop
          unless @options[:promisc]
            next if udp.destination_ip_address != @options.fetch(:ip_address)
          end
          @logger.info "Received: #{udp}"
          @packets_received << udp.snapshot
        rescue Errno::ENETDOWN
          # link is disconnected
          sleep 1
        end
      end
    end
1087087
def size
      raise Erlang::ImproperListError if improper?
      return 0 if empty?
      size = 0
      list = self
      until list.empty?
        list = list.tail
        size += 1
      end
      return size
    end
73980
def assign_attributes(new_attributes)
      if !new_attributes.respond_to?(:stringify_keys)
        raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
      end
      return if new_attributes.empty?

      # stringify keys just like https://github.com/rails/rails/blob/4f99a2186479d5f77460622f2c0f37708b3ec1bc/activemodel/lib/active_model/attribute_assignment.rb#L34
      new_attributes.stringify_keys.each do |k, v|
        setter = :"#{k}="
        if respond_to?(setter)
          public_send(setter, v)
        else
          _attr_json_write_unknown_attribute(k, v)
        end
      end
    end
223223
def big_endian_lengths(bytes)
      lengths = [] # we can't use a hash since the order will be screwed in Ruby 1.8
      lengths << [:options, (bytes.shift << 8) | bytes.shift]                                             # 2 bytes   Length of the "options" field
      lengths << [:id,      (bytes.shift << 8) | bytes.shift]                                             # 2 bytes   Length of the "ID" or "name" field
      lengths << [:type,    (bytes.shift << 8) | bytes.shift]                                             # 2 bytes   Length of the "type" field
      lengths << [:data,    (bytes.shift << 24) | (bytes.shift << 16) | (bytes.shift << 8) | bytes.shift] # 4 bytes   Size of the included file
      lengths
    end
1096042
def method_missing(name, *args)
      name = name.to_s
      last_char = name[-1,1]
      super(name, *args) unless last_char == "=" || last_char == "?"
      attr_name = name[0..-2].to_sym # :foo for 'foo=' or 'foo?'
      if last_char == "="
        @options[attr_name] = args.at(0)
      else
        @options[attr_name]
      end
    end
754177
def file_blob_size(path)
    file_path = Rails.root.join('test/fixtures'.freeze).join(path)
    File.stat(file_path).size
  end
138148
def attrs
      @attrs.inject({}) do |attrs, (key, value)|
        attrs.merge!(key => respond_to?(key) ? send(key) : value)
      end
    end
390061
def method_missing(method, *args, &block)
      
      attribute = ActiveSupport::Inflector.camelize(method.to_s, false)
  
      if attribute =~ /=$/
        attribute = attribute.chop
        return super unless self.attributes.include?(attribute)
        self.changed_attributes[attribute] = args[0]
        self.attributes[attribute] = args[0]
      else
        return super unless self.attributes.include?(attribute)
        self.attributes[attribute]
      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
46776
def run # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
      self.config = Chef::Config.merge!(config)

      # OPTIMIZE: Maybe instead of a flag, infer the graph format from fileext?

      # Parse the configuration options, provide defaults where needed
      output_format = if config[:graphformat]
                        config[:graphformat].to_sym
                      else
                        :png
                      end
      Chef::Log.debug("Output format is: #{output_format}")

      # Determine of a filename has been passed
      filename = if @name_args.size >= 1
                   @name_args[0]
                 else
                   "role-spaghetti.#{output_format}"
                 end
      Chef::Log.debug("Output filename is: #{filename}")

      loaded_roles = loader.find_all_objects(config[:role_path])

      # If we can't find any roles, it's pointless to continue.
      if loaded_roles.empty?
        ui.fatal("No roles were found in role_path: #{config[:role_path]}")
        ui.fatal('Ensure that your knife.rb has the correct path.')
        exit 1
      end

      g = GraphViz.new(:RoleDependencies, type: :digraph,
                                          fontname: 'Verdana', fontsize: 20,
                                          label: "\n\n\nChef Role Dependencies\n",
                                          rankdir: 'LR',
                                          overlap: 'false',
                                          compound: 'true')

      loaded_roles.each do |role_file|
        # Create an absolute path, since some file references include relative paths
        abspath = File.absolute_path(File.join(config[:role_path], role_file))

        # The object_from_file method figures out the ruby/json logic
        role = loader.object_from_file(abspath)

        Chef::Log.debug("Loaded role is: #{role}")

        # OPTIMIZE: Handle environment run_lists

        g.node[:shape] = 'box'
        g.node[:style] = 'rounded'
        g.node[:color] = 'red'
        role_node = g.add_nodes("#{role.name}_role", label: role.name)

        # This logic is to ensure that an embedded role doesn't change color
        role.run_list.each do |rli|
          if rli.role?
            g.node[:shape] = 'box'
            g.node[:style] = 'rounded'
            g.node[:color] = 'red'
            rli_node = g.add_nodes("#{rli.name}_role", label: rli.name)
          else
            g.node[:shape] = 'component'
            g.node[:color] = 'blue'
            rli_node = g.add_nodes(rli.name)
          end

          g.add_edges(role_node, rli_node)
        end
      end

      # Let's write out the graph to a file
      if config[:neatograph]
        g.output(output_format => filename.to_s, :use => 'neato')
      else
        # default to dot
        g.output(output_format => filename.to_s)
      end

      ui.msg("A Role dependency graph has been written to #{filename}")
    end
277158
def new
      @image = Cmtool::Image.new

      respond_to do |format|
        format.html # new.html.erb
        format.xml  { render :xml => @image }
      end
    end
698531
def update
      param_key = ActiveModel::Naming.param_key(@content)

      respond_to do |format|
        if @content.update_attributes(params[param_key])
          format.json { render json: @content }
        else
          format.json { render json: @content.errors, status: :unprocessable_entity }
        end
      end
    end
1297285
def size
      clients = @clients.values.inject(0) {|sum, arr| sum + arr.size }
      clients + @servers.size + @components.size
    end
577844
def attributes
      self.class::ATTRIBUTES_NAMES.inject({}) do |attribs, attrib_name|
        value = self.send(attrib_name)
        attribs[attrib_name] = value unless value.nil?
        attribs
      end
    end
132989
def stretch!(*arys)
      max_size = (arys + [self]).collect { |a| a.length }.max
      self[max_size - 1] = nil unless self.length == max_size
      return self
    end
804980
def resolve
    options[:rootpath]   ||= Pathname.pwd
    options[:rootpath]     = Pathname.new(options[:rootpath])
    options[:namespaces] ||= []
    options[:preset]     ||= resolve_preset

    if %w{rails rails-engine}.include?(options[:preset])
      options[:rootpath]     = detect_engine_root                                if options[:preset]     == 'rails-engine'
      options[:namespaces]   = load_rails_default_namespaces(options[:rootpath]) if options[:namespaces] == []
      options[:basepath]   ||= options[:rootpath] + 'config'
    else
      options[:basepath]   ||= options[:rootpath]
    end

    options[:encryption_keys]   = Keys::Encryption.resolve(filenames:  options[:encryption_keys],
                                                           namespaces: options[:namespaces],
                                                           rootpath:   options[:rootpath])
    options[:decryption_keys]   = Keys::Decryption.resolve(filenames:  options[:decryption_keys],
                                                           namespaces: options[:namespaces],
                                                           rootpath:   options[:rootpath])
    options[:basepath]          = Pathname.new(options[:basepath])
    options[:files]           ||= [
                                    options[:basepath] + 'settings*.yml',
                                    options[:basepath] + 'settings',
                                  ]

    options
  end
1143209
def method_missing(name, *args, &block)
      if @type.has_attribute?(name.to_s)
        __attribute__(name, *args)
      else
        __tag__(name, *args, &block)
      end
    end