Sha256: eb3807e47786ff509b9bfad572f6636a50b61bb66d767984aca96e264834eea8

Contents?: true

Size: 1007 Bytes

Versions: 46

Compression:

Stored size: 1007 Bytes

Contents

module Softcover
  class BaseConfig

    DEFAULTS = {
      host: 'https://www.softcover.io'
    }

    PATH = '.'

    class << self
      def [](key)
        store.transaction do
          store[key]
        end || DEFAULTS[key.to_sym]
      end

      def []=(key, value)
        store.transaction do
          store[key] = value
        end
      end

      def read
        puts `cat #{file_path}`
      end

      def remove
        File.delete(file_path) if exists?
      end

      def exists?
        File.exists?(file_path)
      end

      protected
        def store
          require 'yaml/store'
          @store ||= begin
             YAML::Store.new(file_path)
          end
        end

        def file_path
          File.expand_path(self::PATH).tap do |path|
            path.gsub!(/$/,"-test") if Softcover::test?
          end
        end
    end
  end

  class BookConfig < BaseConfig
    PATH = ".softcover-book"
  end

  class Config < BaseConfig
    PATH = "~/.softcover"
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
softcover-0.9.12 lib/softcover/config.rb
softcover-0.9.11 lib/softcover/config.rb
softcover-0.9.10 lib/softcover/config.rb
softcover-0.9.9 lib/softcover/config.rb
softcover-0.9.8 lib/softcover/config.rb
softcover-0.9.7 lib/softcover/config.rb
softcover-0.9.6 lib/softcover/config.rb
softcover-0.9.5 lib/softcover/config.rb
softcover-0.9.4 lib/softcover/config.rb
softcover-0.9.3 lib/softcover/config.rb
softcover-0.9.2 lib/softcover/config.rb
softcover-0.9.1 lib/softcover/config.rb
softcover-0.9.0 lib/softcover/config.rb
softcover-0.8.9 lib/softcover/config.rb
softcover-0.8.8 lib/softcover/config.rb
softcover-0.8.7 lib/softcover/config.rb
softcover-0.8.6 lib/softcover/config.rb
softcover-0.8.5 lib/softcover/config.rb
softcover-0.8.4 lib/softcover/config.rb
softcover-0.8.3 lib/softcover/config.rb