Class: Luca::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/luca/project.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Project

Returns a new instance of Project.



52
53
54
55
# File 'lib/luca/project.rb', line 52

def initialize options={}
  @path = options[:path]
  @name = options[:name] || File.basename(@path)
end

Class Attribute Details

.storageObject

Returns the value of attribute storage.



4
5
6
# File 'lib/luca/project.rb', line 4

def storage
  @storage
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/luca/project.rb', line 8

def name
  @name
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/luca/project.rb', line 8

def path
  @path
end

Class Method Details

.create(attributes = {}) ⇒ Object



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

def self.create attributes={}
  store.create(attributes)
end

.find_by_name(name) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/luca/project.rb', line 42

def self.find_by_name name
  data = index.detect do |project_data|
    project_data['name'] == name
  end

  return nil unless data

  new(path: data['path'], name: data['name'])
end

.find_by_path(path) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/luca/project.rb', line 23

def self.find_by_path path
  data = index.detect do |project_data|
    project_data['path'] == path
  end
  
  return nil unless data 

  new(path: data['path'], name: data['name'])    
end

.find_or_create_by_name(name, attributes = {}) ⇒ Object



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

def self.find_or_create_by_name(name, attributes={})
  if existing = find_by_name(name)
    return existing
  else
    attributes[:name] = name  
    create(attributes)
  end
end

.indexObject



19
20
21
# File 'lib/luca/project.rb', line 19

def self.index
  store.index
end

.storeObject



11
12
13
# File 'lib/luca/project.rb', line 11

def self.store
  self.storage ||= Luca::Collection.new(namespace:"projects",backend_type:"file")
end

Instance Method Details

#appObject



65
66
67
# File 'lib/luca/project.rb', line 65

def app
  luca_application
end

#as_jsonObject



57
58
59
# File 'lib/luca/project.rb', line 57

def as_json
  {path: path, name: name}
end

#gitObject



61
62
63
# File 'lib/luca/project.rb', line 61

def git
  @git ||= Grit::Repo.new(path) 
end

#luca_applicationObject



69
70
71
# File 'lib/luca/project.rb', line 69

def luca_application
  @luca_application ||= LucaApplication.new(name.capitalize, root: path)
end