Sha256: 50a241338e60b5ef9d14ee40b3691addbf680ca55ff587f00bbf6173c149fa42

Contents?: true

Size: 908 Bytes

Versions: 106

Compression:

Stored size: 908 Bytes

Contents

require "fileutils"
require "yaml"

module CC
  module CLI
    class FileStore
      # This class is not supposed to be directly used. It should be sublcassed
      # and a few constants need to be defined on the sublass to be usable.
      #
      # FILE_NAME is the name of the file this class wraps.

      def initialize
        load_data
      end

      def save
        return false unless File.exist? self.class::FILE_NAME

        File.open(self.class::FILE_NAME, "w") do |f|
          YAML.dump data, f
        end

        true
      end

      private

      attr_reader :data

      def load_data
        @data =
          if File.exist? self.class::FILE_NAME
            File.open(self.class::FILE_NAME, "r:bom|utf-8") do |f|
              YAML.safe_load(f, [Time], [], false, self.class::FILE_NAME) || {}
            end
          else
            {}
          end
      end
    end
  end
end

Version data entries

106 entries across 106 versions & 2 rubygems

Version Path
codeclimate-0.68.0 lib/cc/cli/file_store.rb
codeclimate-0.67.0 lib/cc/cli/file_store.rb
codeclimate-0.66.0 lib/cc/cli/file_store.rb
codeclimate-0.65.0 lib/cc/cli/file_store.rb
codeclimate-0.64.0 lib/cc/cli/file_store.rb
codeclimate-0.63.7 lib/cc/cli/file_store.rb
codeclimate-0.63.6 lib/cc/cli/file_store.rb
codeclimate-0.63.5 lib/cc/cli/file_store.rb
codeclimate-0.63.4 lib/cc/cli/file_store.rb
codeclimate-0.63.3 lib/cc/cli/file_store.rb
codeclimate-0.63.2 lib/cc/cli/file_store.rb
codeclimate-0.63.1 lib/cc/cli/file_store.rb
codeclimate-0.63.0 lib/cc/cli/file_store.rb
codeclimate-0.62.0 lib/cc/cli/file_store.rb
codeclimate-0.61.1 lib/cc/cli/file_store.rb
codeclimate-0.61.0 lib/cc/cli/file_store.rb
codeclimate-0.60.1 lib/cc/cli/file_store.rb
codeclimate-0.60.0 lib/cc/cli/file_store.rb
codeclimate-0.59.1 lib/cc/cli/file_store.rb
codeclimate-0.59.0 lib/cc/cli/file_store.rb