Sha256: 776ae63f4cfe3c3dae07ebf578e29d0ea9d7e9c94d2303a30c94b05e20b07cdc

Contents?: true

Size: 1.07 KB

Versions: 126

Compression:

Stored size: 1.07 KB

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(path).tap do |full_path|
            full_path.gsub!(/$/,"-test") if Softcover::test?
          end
        end
    end
  end

  class BookConfig < BaseConfig
    def self.path
      ".softcover-book"
    end
  end

  class Config < BaseConfig
    def self.path
      File.exists?(".softcover") ? ".softcover" : "~/.softcover"
    end
  end
end

Version data entries

126 entries across 126 versions & 2 rubygems

Version Path
softcover-1.10.4 lib/softcover/config.rb
softcover-1.10.3 lib/softcover/config.rb
softcover-1.10.2 lib/softcover/config.rb
softcover-1.10.1 lib/softcover/config.rb
softcover-1.10.0 lib/softcover/config.rb
softcover-1.9.1 lib/softcover/config.rb
softcover-1.9.0 lib/softcover/config.rb
softcover-1.8.3 lib/softcover/config.rb
softcover-1.8.2 lib/softcover/config.rb
softcover-1.8.1 lib/softcover/config.rb
softcover-1.8.0 lib/softcover/config.rb
softcover-1.7.5 lib/softcover/config.rb
softcover-1.7.4 lib/softcover/config.rb
softcover-1.7.3 lib/softcover/config.rb
softcover-1.7.2 lib/softcover/config.rb
softcover-1.7.1 lib/softcover/config.rb
softcover-1.7.0 lib/softcover/config.rb
softcover-1.6.5 lib/softcover/config.rb
softcover-1.6.4 lib/softcover/config.rb
softcover-1.6.3 lib/softcover/config.rb