Class: Shippy::Repo
- Inherits:
-
Object
- Object
- Shippy::Repo
- Defined in:
- lib/shippy/repo.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
- .current ⇒ Object
- .current=(repo) ⇒ Object
- .define(&block) ⇒ Object
- .load_app(name) ⇒ Object
- .with(repo) ⇒ Object
Instance Method Summary collapse
- #app_names ⇒ Object
- #define(&block) ⇒ Object
- #each(&block) ⇒ Object
- #each_app(&block) ⇒ Object
- #hooks_for(app) ⇒ Object
-
#initialize ⇒ Repo
constructor
A new instance of Repo.
- #load_definitions(pattern: "**") ⇒ Object
Constructor Details
#initialize ⇒ Repo
Returns a new instance of Repo.
34 35 36 |
# File 'lib/shippy/repo.rb', line 34 def initialize @data = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/shippy/repo.rb', line 3 def data @data end |
Class Method Details
.current ⇒ Object
6 7 8 |
# File 'lib/shippy/repo.rb', line 6 def current Thread.current[:repo] end |
.current=(repo) ⇒ Object
10 11 12 |
# File 'lib/shippy/repo.rb', line 10 def current=(repo) Thread.current[:repo] = repo end |
.define(&block) ⇒ Object
23 24 25 |
# File 'lib/shippy/repo.rb', line 23 def define(&block) current.define(&block) end |
.load_app(name) ⇒ Object
27 28 29 30 31 |
# File 'lib/shippy/repo.rb', line 27 def load_app(name) repo = new repo.load_definitions(pattern: name) repo.data.fetch(name) end |
.with(repo) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/shippy/repo.rb', line 14 def with(repo) old_repo = current self.current = repo yield ensure self.current = old_repo end |
Instance Method Details
#app_names ⇒ Object
66 67 68 |
# File 'lib/shippy/repo.rb', line 66 def app_names data.keys end |
#define(&block) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/shippy/repo.rb', line 38 def define(&block) name = caller .reject { |path| path.match(/lib\/shippy/) } .find { |path| path.match(/docker-compose\.rb/) }.split(":", 2).first name = File.basename(File.dirname(name)) data[name] = Compose.new(name, &block) end |
#each(&block) ⇒ Object
58 59 60 |
# File 'lib/shippy/repo.rb', line 58 def each(&block) data.each(&block) end |
#each_app(&block) ⇒ Object
62 63 64 |
# File 'lib/shippy/repo.rb', line 62 def each_app(&block) data.values.each(&block) end |
#hooks_for(app) ⇒ Object
54 55 56 |
# File 'lib/shippy/repo.rb', line 54 def hooks_for(app) data.fetch(app).hooks end |
#load_definitions(pattern: "**") ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/shippy/repo.rb', line 46 def load_definitions(pattern: "**") self.class.with(self) do Pathname.glob("apps/#{pattern}/docker-compose.rb") .map(&:expand_path) .each { |path| load path } end end |