Sha256: 6160d6f75c6aeb7c8e89c652eacdf587b6244df84b5427a1ef176f7076dda409

Contents?: true

Size: 741 Bytes

Versions: 5

Compression:

Stored size: 741 Bytes

Contents

require 'json'

module CocoaPods
  module AppGroup
    class Store
      attr_reader :path

      def initialize(path = default_root)
        @path = path
      end

      def read(name)
        table[name.to_s]
      end

      def write(name, value)
        saving { table[name.to_s] = value }
      end

      private

      def default_root
        Pod::Config.instance.installation_root.join('.cocoapods_appgroup')
      end

      def table
        @table ||= JSON.parse File.read(path)
      rescue Errno::ENOENT, JSON::ParserError
        @table ||= {}
      end

      def saving(&f)
        f.call.tap do
          File.open(path, 'w+') do |io|
            JSON.dump table, io
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cocoapods-app_group-0.4.1 lib/cocoapods/app_group/store.rb
cocoapods-app_group-0.4.0 lib/cocoapods/app_group/store.rb
cocoapods-app_group-0.3.0 lib/cocoapods/app_group/store.rb
cocoapods-app_group-0.2.0 lib/cocoapods/app_group/store.rb
cocoapods-app_group-0.1.0 lib/cocoapods/app_group/store.rb