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.79.0 lib/cc/cli/file_store.rb
codeclimate-0.78.1 lib/cc/cli/file_store.rb
codeclimate-0.78.0 lib/cc/cli/file_store.rb
codeclimate-0.77.0 lib/cc/cli/file_store.rb
codeclimate-0.76.0 lib/cc/cli/file_store.rb
codeclimate-0.75.0 lib/cc/cli/file_store.rb
codeclimate-0.74.0 lib/cc/cli/file_store.rb
codeclimate-0.73.0 lib/cc/cli/file_store.rb
codeclimate-0.72.0 lib/cc/cli/file_store.rb
codeclimate-0.71.2 lib/cc/cli/file_store.rb
codeclimate-0.71.1 lib/cc/cli/file_store.rb
codeclimate-0.71.0 lib/cc/cli/file_store.rb
codeclimate-0.70.6 lib/cc/cli/file_store.rb
codeclimate-0.70.5 lib/cc/cli/file_store.rb
codeclimate-0.70.4 lib/cc/cli/file_store.rb
codeclimate-0.70.3 lib/cc/cli/file_store.rb
codeclimate-0.70.2 lib/cc/cli/file_store.rb
codeclimate-0.70.1 lib/cc/cli/file_store.rb
codeclimate-0.70.0 lib/cc/cli/file_store.rb
codeclimate-0.69.0 lib/cc/cli/file_store.rb