Class: Canals::Repository
- Inherits:
-
Object
- Object
- Canals::Repository
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/canals/repository.rb
Constant Summary collapse
- ENVIRONMENTS =
:environments- TUNNELS =
:tunnels
Instance Method Summary collapse
- #add(options, save = true) ⇒ Object
- #add_environment(environment, save = true) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #environment(name = nil) ⇒ Object
- #environments ⇒ Object
- #get(name) ⇒ Object
-
#initialize(root = nil) ⇒ Repository
constructor
A new instance of Repository.
- #save! ⇒ Object
Constructor Details
#initialize(root = nil) ⇒ Repository
Returns a new instance of Repository.
14 15 16 17 |
# File 'lib/canals/repository.rb', line 14 def initialize(root = nil) @root = root @repo = load_repository(repo_file) end |
Instance Method Details
#add(options, save = true) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/canals/repository.rb', line 29 def add(, save=true) @repo[TUNNELS][.name] = .to_hash if .env_name.nil? && !.env.nil? && .env.is_default? @repo[TUNNELS][.name]["env"] = .env.name end save! if save end |
#add_environment(environment, save = true) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/canals/repository.rb', line 42 def add_environment(environment, save=true) if environment.is_default? @repo[ENVIRONMENTS].each { |name, env| env.delete("default") } end if @repo[ENVIRONMENTS].empty? environment.default = true end @repo[ENVIRONMENTS][environment.name] = environment.to_hash save! if save end |
#each(&block) ⇒ Object
21 22 23 |
# File 'lib/canals/repository.rb', line 21 def each(&block) @repo[TUNNELS].map{ |n, r| Canals::CanalOptions.new(r) }.each(&block) end |
#empty? ⇒ Boolean
25 26 27 |
# File 'lib/canals/repository.rb', line 25 def empty? @repo[TUNNELS].empty? end |
#environment(name = nil) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/canals/repository.rb', line 60 def environment(name=nil) if name.nil? args = @repo[ENVIRONMENTS].select{ |n,e| e["default"] }.values[0] else args = @repo[ENVIRONMENTS][name] end Canals::Environment.new(args) if !args.nil? end |
#environments ⇒ Object
69 70 71 |
# File 'lib/canals/repository.rb', line 69 def environments @repo[ENVIRONMENTS].map { |n, e| Canals::Environment.new(e) } end |
#get(name) ⇒ Object
37 38 39 40 |
# File 'lib/canals/repository.rb', line 37 def get(name) return nil if !@repo[:tunnels].has_key? name CanalOptions.new(@repo[:tunnels][name]) end |
#save! ⇒ Object
53 54 55 56 57 58 |
# File 'lib/canals/repository.rb', line 53 def save! FileUtils.mkdir_p(repo_file.dirname) File.open(repo_file, 'w') do |file| file.write(Psych.dump(@repo)) end end |