Class: Intent::Core::Projects

Inherits:
Object
  • Object
show all
Defined in:
lib/intent/core/projects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_path) ⇒ Projects

Returns a new instance of Projects.



7
8
9
10
# File 'lib/intent/core/projects.rb', line 7

def initialize(db_path)
  @ledger_path = db_path
  @list = List.new(db_path)
end

Instance Attribute Details

#ledger_pathObject (readonly)

Returns the value of attribute ledger_path.



5
6
7
# File 'lib/intent/core/projects.rb', line 5

def ledger_path
  @ledger_path
end

#listObject (readonly)

Returns the value of attribute list.



4
5
6
# File 'lib/intent/core/projects.rb', line 4

def list
  @list
end

Instance Method Details

#add_directory!(path, project, id, computer) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/intent/core/projects.rb', line 37

def add_directory!(path, project, id, computer)
  record = Record.new([
    Date.today,
    path,
    project,
    "is:directory",
    "id:#{id}",
    "computer:#{computer}"
  ].join(' '))

  @list.append(record)
  @list.save!
end

#allObject



12
13
14
# File 'lib/intent/core/projects.rb', line 12

def all
  list.by_not_done
end

#all_tokensObject



16
17
18
# File 'lib/intent/core/projects.rb', line 16

def all_tokens
  all.map { |item| item.projects.first }.uniq
end

#linked_directory(path) ⇒ Object



20
21
22
# File 'lib/intent/core/projects.rb', line 20

def linked_directory(path)
  all.find { |item| item.text == path && ['repository', 'directory'].include?(item.tags[:is]) }
end

#sync!Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/intent/core/projects.rb', line 24

def sync!
  ledger_file = File.basename(ledger_path)

  if repo.status.changed?(ledger_file)
    repo.add(ledger_file)
    repo.commit("Synchronizing projects [#{Time.new}]")
    repo.push
    true # Result:OK
  else
    false # Result::NO_CHANGES
  end
end