Sha256: ea096432b01582695082aa234422721d242ac0ae48d5caffb547a900e8f61290

Contents?: true

Size: 868 Bytes

Versions: 6

Compression:

Stored size: 868 Bytes

Contents

module Xray

  def self.config
    @@config ||= Config.new
  end

  class Config
    attr_accessor :editor

    CONFIG_FILE = "#{Dir.home}/.xrayconfig"
    DEFAULT_EDITOR = '/usr/local/bin/subl'

    def editor
      load_config[:editor]
    end

    def editor=(new_editor)
      if new_editor && new_editor != editor
        write_config(editor: new_editor)
        true
      else
        false
      end
    end

    def to_yaml
      {editor: editor}.to_yaml
    end

    private

    def write_config(new_config)
      config = load_config.merge(new_config)
      File.open(CONFIG_FILE, 'w') { |f| f.write(config.to_yaml) }
    end

    def load_config
      default_config.merge(local_config)
    end

    def local_config
      YAML.load_file(CONFIG_FILE)
    rescue
      {}
    end

    def default_config
      { editor: DEFAULT_EDITOR }
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
xray-rails-0.1.6 lib/xray/config.rb
xray-rails-0.1.5 lib/xray/config.rb
xray-rails-0.1.4 lib/xray/config.rb
xray-rails-0.1.3 lib/xray/config.rb
xray-rails-0.1.2 lib/xray/config.rb
xray-rails-0.1.1 lib/xray/config.rb