Class: Luca::Project
- Inherits:
-
Object
- Object
- Luca::Project
- Defined in:
- lib/luca/project.rb
Class Attribute Summary collapse
-
.storage ⇒ Object
Returns the value of attribute storage.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
- .create(attributes = {}) ⇒ Object
- .find_by_name(name) ⇒ Object
- .find_by_path(path) ⇒ Object
- .find_or_create_by_name(name, attributes = {}) ⇒ Object
- .index ⇒ Object
- .store ⇒ Object
Instance Method Summary collapse
- #app ⇒ Object
- #as_json ⇒ Object
- #git ⇒ Object
-
#initialize(options = {}) ⇒ Project
constructor
A new instance of Project.
- #luca_application ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Project
Returns a new instance of Project.
52 53 54 55 |
# File 'lib/luca/project.rb', line 52 def initialize ={} @path = [:path] @name = [:name] || File.basename(@path) end |
Class Attribute Details
.storage ⇒ Object
Returns the value of attribute storage.
4 5 6 |
# File 'lib/luca/project.rb', line 4 def storage @storage end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/luca/project.rb', line 8 def name @name end |
#path ⇒ Object
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 |
.index ⇒ Object
19 20 21 |
# File 'lib/luca/project.rb', line 19 def self.index store.index end |
.store ⇒ Object
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
#app ⇒ Object
65 66 67 |
# File 'lib/luca/project.rb', line 65 def app luca_application end |
#as_json ⇒ Object
57 58 59 |
# File 'lib/luca/project.rb', line 57 def as_json {path: path, name: name} end |
#git ⇒ Object
61 62 63 |
# File 'lib/luca/project.rb', line 61 def git @git ||= Grit::Repo.new(path) end |
#luca_application ⇒ Object
69 70 71 |
# File 'lib/luca/project.rb', line 69 def luca_application @luca_application ||= LucaApplication.new(name.capitalize, root: path) end |