Git Product home page Git Product logo

xdg's Introduction

XDG Standards for Ruby

Homepage | Source Code | Report Issue | Mailing List | Chat Room

Build Status

Introduction

XDG provides an easy to use Ruby library for working with XDG standards.

Presently, it only supports the XDG Base Directory Standard.

If your program utilizes user or system-wide support files (e.g. configuration files), you owe it to yourself to checkout the XDG base directory standard.

You can learn more about the standard at: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

How to Use

For working with XDG base directories, XDG provides a very simple yet flexible interface, XDG[]. Let's say you want to work with the $XDG_CONFIG_HOME directory. Simply use:

XDG['CONFIG_HOME']

This will give you access to a number of useful methods all tied into the user's personal configuration directory. Some examples:

XDG['CONFIG_HOME'].glob(pattern)
XDG['CONFIG_HOME'].select(pattern){ |path| ... }
XDG['CONFIG_HOME'].find(pattern){ |path| ... }

The same holds true for the other base directories.

XDG['DATA_HOME']
XDG['DATA_DIRS']

XDG['CACHE_HOME']
XDG['CACHE_DIRS']

By leaving out the last qualifier, XDG will provide an interface that ties into both the HOME and DIRS paths.

XDG['DATA']
XDG['CONFIG']
XDG['CACHE']

If you know XDG these are pretty much self-explanatory. But see the YARD-based API documentation for further specifics.

Extended Functionality

The Ruby XDG module also provides extended functionality not part of the standard specification. These extensions are simply add-on functionality deemed useful, or implementations of proposals being discussed for a possible future version of the standard.

XDG['CONFIG_WORK']
XDG['CACHE_WORK']

See the API documentation to learn more. Note that the extended modules are subject to greater potential for change as they are still being refined.

Base Directory Mixin

XDG provides a convenient base directory mixin that can provide handy a interface to a classes.

class MyAppConfig
  include XDG::BaseDir::Mixin

  def subdirectory
    'myapp'
  end
end

c = MyAppConfig.new

c.config.home.to_s  #=> '~/.config/myapp'

Legacy API

Version 2.0+ of library marks a major departure from the earlier "fluid" notation of previous releases. Where as one used to do:

XDG.data.home

With the new API one now does:

XDG['DATA_HOME']

This was done for a few reasons, but primarily because it reflects more closely Ruby's interface to the environment variables themselves, e.g.

ENV['XDG_DATA_HOME']

If you prefer the older style, a compatibility layer is provided. You will need to load:

require 'xdg/base_dir/legacy'

However we STRONGLY RECOMMEND that you do not use the legacy API --use it only if you need to keep some old code working and don't have time to update it at the moment. Sometime in the future the legacy API will be deprecated.

How to Install

Using RubyGems:

$ sudo gem install xdg

Installing the tarball requires Ruby Setup (see http://rubyworks.github.com/setup).

$ tar -xvzf xdg-0.5.2
$ cd xdg-0.5.2
$ sudo setup.rb all

Development

GitHub hosts our source code and issue ticket system.

To contribute to the project please fork the repository, ideally, create a new topic branch for your work, and submit a pull request.

Copyright & License

Copyright (c) 2008 Rubyworks

Distributed under the terms of the FreeBSD license.

See LICENSE.txt file for details.

xdg's People

Contributors

trans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xdg's Issues

2.2.4 release broken

index.rb is missing from the released gem

irb(main):001:0> require 'xdg'
LoadError: cannot load such file -- /var/lib/gems/2.3.0/gems/xdg-2.2.4/lib/xdg/index
	from /var/lib/gems/2.3.0/gems/xdg-2.2.4/lib/xdg.rb:28:in `require_relative'
	from /var/lib/gems/2.3.0/gems/xdg-2.2.4/lib/xdg.rb:28:in `<module:XDG>'
	from /var/lib/gems/2.3.0/gems/xdg-2.2.4/lib/xdg.rb:26:in `<top (required)>'
	from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
	from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
	from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
	from (irb):1
	from /usr/bin/irb:11:in `<main>'

Release new gem version?

Would you mind to release a new gem version with those rbconfig changes included? Thank you very much in advance.

Cheers
dg

Would it be possible to switch gem ownership?

Overview

It doesn't look like this project is maintained anymore and was wondering if I could take ownership of the Ruby Gems namespace for deploying new versions of the XDG library? This project could remain as is but I'd end up publishing a new XDG project with the ability to publish newer versions of the XDG library to Ruby Gems. Would the maintainers of this project be willing to do that?

Details

I maintain the Runcom project which uses XDG under the covers as well as provides extended functionality for application developers. While the project currently doesn't support all of the XDG capabilities, I'm working on a feature branch which will provide support for all XDG environment variables. I plan to release this at the end of this year or first of the new year as soon as Ruby 2.6 is released. ๐ŸŽ‰ My version of XDG does use a different API but the functionality that people need won't change.

Next Actions

If any of this sounds good, please comment here and we can figure out a path forward. Thanks!

Concept for potentially better interface

Where as currently we have a partial method/constant interface, e.g. XDG::Config.home or XDG.config.home. It is possible to use a complete constant and make it act both like an string/array and a pathname.

XDG::CONFIG::HOME  => "~/.config"
XDG::CONFIG::DIRS  => ["/etc/xdg", "/etc"]

But still have a file based set of methods too:

XDG::CONFIG::DIRS.find(pattern){ |f| .... }
XDG::CONFIG::DIRS.glob(pattern){ |f| .... }

And to include both home and dirs:

XDG::CONFIG.find(pattern){ |f| .... }
XDG::CONFIG.glob(pattern){ |f| .... }

(Might use a different name for #find since that's used by Enumerable already, but not sure what that might be.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.