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-fede-0.85.40 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.39 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.38 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.37 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.36 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.35 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.33 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.32 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.31 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.30 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.21 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.24 lib/cc/cli/file_store.rb
codeclimate-fede-0.85.23 lib/cc/cli/file_store.rb
codeclimate-0.85.23 lib/cc/cli/file_store.rb
codeclimate-0.85.22 lib/cc/cli/file_store.rb
codeclimate-0.85.21 lib/cc/cli/file_store.rb
codeclimate-0.85.19 lib/cc/cli/file_store.rb
codeclimate-0.85.18 lib/cc/cli/file_store.rb
codeclimate-0.85.17 lib/cc/cli/file_store.rb
codeclimate-0.85.15 lib/cc/cli/file_store.rb