Class: Cult::Project
- Inherits:
-
Object
- Object
- Cult::Project
- Defined in:
- lib/cult/project.rb
Constant Summary collapse
- CULT_RC =
'.cultrc'
Instance Attribute Summary collapse
-
#cult_version ⇒ Object
Returns the value of attribute cult_version.
-
#default_ip_protocol ⇒ Object
Returns the value of attribute default_ip_protocol.
- #default_provider ⇒ Object
-
#git_integration ⇒ Object
(also: #git?)
Returns the value of attribute git_integration.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #constructed? ⇒ Boolean (also: #exist?)
- #cultrc ⇒ Object
- #development? ⇒ Boolean
- #drivers ⇒ Object
- #env ⇒ Object
- #execute_cultrc ⇒ Object
- #git_branch ⇒ Object
- #git_commit_id(short: false) ⇒ Object
-
#initialize(path) ⇒ Project
constructor
A new instance of Project.
- #inspect ⇒ Object (also: #to_s)
- #location_of(file) ⇒ Object
- #name ⇒ Object
- #nodes ⇒ Object
- #providers ⇒ Object
- #relative_path(obj_path) ⇒ Object
- #remote_path ⇒ Object
- #roles ⇒ Object
Constructor Details
#initialize(path) ⇒ Project
Returns a new instance of Project.
13 14 15 16 |
# File 'lib/cult/project.rb', line 13 def initialize(path) @default_ip_protocol = :ipv4 @path = path end |
Instance Attribute Details
#cult_version ⇒ Object
Returns the value of attribute cult_version.
10 11 12 |
# File 'lib/cult/project.rb', line 10 def cult_version @cult_version end |
#default_ip_protocol ⇒ Object
Returns the value of attribute default_ip_protocol.
11 12 13 |
# File 'lib/cult/project.rb', line 11 def default_ip_protocol @default_ip_protocol end |
#default_provider ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cult/project.rb', line 88 def default_provider @default_provider_instance ||= begin case @default_provider when Cult::Provider @default_provider when nil; providers.first else providers[@default_provider] end end end |
#git_integration ⇒ Object Also known as: git?
Returns the value of attribute git_integration.
129 130 131 |
# File 'lib/cult/project.rb', line 129 def git_integration @git_integration end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/cult/project.rb', line 9 def path @path end |
Class Method Details
.from_cwd ⇒ Object
125 126 127 |
# File 'lib/cult/project.rb', line 125 def self.from_cwd locate Dir.getwd end |
.locate(path) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cult/project.rb', line 109 def self.locate(path) path = File.(path) loop do return nil if path == '/' unless File.directory?(path) path = File.dirname(path) end candidate = File.join(path, CULT_RC) return new(path) if File.exist?(candidate) path = File.dirname(path) end end |
Instance Method Details
#constructed? ⇒ Boolean Also known as: exist?
61 62 63 |
# File 'lib/cult/project.rb', line 61 def constructed? File.exist?(cultrc) end |
#cultrc ⇒ Object
24 25 26 |
# File 'lib/cult/project.rb', line 24 def cultrc location_of(CULT_RC) end |
#development? ⇒ Boolean
158 159 160 |
# File 'lib/cult/project.rb', line 158 def development? env == 'development' end |
#drivers ⇒ Object
102 103 104 105 106 |
# File 'lib/cult/project.rb', line 102 def drivers @drivers ||= begin Cult::Drivers.all end end |
#env ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'lib/cult/project.rb', line 147 def env ENV['CULT_ENV'] || begin if git_branch&.match(/\bdev(el(opment)?)?\b/) 'development' else 'production' end end end |
#execute_cultrc ⇒ Object
29 30 31 |
# File 'lib/cult/project.rb', line 29 def execute_cultrc load(cultrc) end |
#git_branch ⇒ Object
132 133 134 135 136 137 |
# File 'lib/cult/project.rb', line 132 def git_branch res = %x(git -C #{Shellwords.escape(path)} branch --no-color) if res && (m = res.match(/^\* (.*)/)) return m[1].chomp end end |
#git_commit_id(short: false) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/cult/project.rb', line 139 def git_commit_id(short: false) short = short ? "--short" : '' cmd = "git -C #{Shellwords.escape(path)} rev-parse #{short} " + "--verify HEAD" %x(#{cmd}).chomp end |
#inspect ⇒ Object Also known as: to_s
34 35 36 |
# File 'lib/cult/project.rb', line 34 def inspect "\#<#{self.class.name} name=#{name.inspect} path=#{path.inspect}>" end |
#location_of(file) ⇒ Object
40 41 42 |
# File 'lib/cult/project.rb', line 40 def location_of(file) File.join(path, file) end |
#name ⇒ Object
19 20 21 |
# File 'lib/cult/project.rb', line 19 def name File.basename(path) end |
#nodes ⇒ Object
66 67 68 69 70 |
# File 'lib/cult/project.rb', line 66 def nodes @nodes ||= begin Node.all(self) end end |
#providers ⇒ Object
80 81 82 83 84 |
# File 'lib/cult/project.rb', line 80 def providers @providers ||= begin Cult::Provider.all(self) end end |
#relative_path(obj_path) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/cult/project.rb', line 45 def relative_path(obj_path) prefix = "#{path}/" if obj_path.start_with?(prefix) return obj_path[prefix.length .. -1] end fail ArgumentError, "#{path} isn't in the project" end |
#remote_path ⇒ Object
56 57 58 |
# File 'lib/cult/project.rb', line 56 def remote_path "cult" end |