Module: Urls

Extended by:
API
Defined in:
lib/urls.rb,
lib/urls/runner.rb,
lib/urls/version.rb

Defined Under Namespace

Modules: API Classes: Runner

Constant Summary collapse

VERSION =
'0.1.0'

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from API

copy

Class Attribute Details

.browserObject

command to open urls in browser



15
16
17
# File 'lib/urls.rb', line 15

def browser
  @browser
end

.dbObject

database for datamapper. Can be a uri string or a hash of options



13
14
15
# File 'lib/urls.rb', line 13

def db
  @db
end

Class Method Details

.add_tag(url, tags) ⇒ Object



28
29
30
# File 'lib/urls.rb', line 28

def self.add_tag(url, tags)
  tag('add', url, '--tags', *tags)
end

.homeObject



5
6
7
8
9
# File 'lib/urls.rb', line 5

def self.home
  @home ||= (ENV['URLS_HOME'] || File.join(Dir.home, '.urls')).tap do |dir|
    FileUtils.mkdir_p(dir)
  end
end

.setupObject



20
21
22
23
24
25
26
# File 'lib/urls.rb', line 20

def self.setup
  self.db ||= { adapter: 'yaml', path: home }
  DataMapper.setup(:default, db)
  DataMapper.finalize
  DataMapper.auto_upgrade!
  ENV['TAG_MODEL'] = 'urls'
end

.tag(*cmds) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/urls.rb', line 32

def self.tag(*cmds)
  options = cmds[-1].is_a?(Hash) ? cmds.pop : {}
  ENV['BOSONRC'] = '' # don't want urlsrc to pass as tagrc
  if options[:capture]
    `tag #{cmds.join(' ')}`
  else
    system('tag', *cmds)
  end
end

.tagged_itemsObject



42
43
44
45
46
47
# File 'lib/urls.rb', line 42

def self.tagged_items
  tag('items', capture: true).split("\n").inject({}) do |h,line|
    url, tags = line.split("\t")
    h.update url => tags
  end
end