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
- #delete(name, save = true) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #environment(name = nil) ⇒ Object
- #environments ⇒ Object
- #get(name) ⇒ Object
- #has?(name) ⇒ Boolean
-
#initialize(root = nil) ⇒ Repository
constructor
A new instance of Repository.
- #save! ⇒ Object
Constructor Details
#initialize(root = nil) ⇒ Repository
Returns a new instance of Repository.
15 16 17 18 |
# File 'lib/canals/repository.rb', line 15 def initialize(root = nil) @root = root @repo = load_repository(repo_file) end |
Instance Method Details
#add(options, save = true) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/canals/repository.rb', line 30 def add(, save=true) @repo[TUNNELS][.name.to_sym] = .to_hash if .env_name.nil? && !.env.nil? && .env.is_default? @repo[TUNNELS][.name.to_sym][:env] = .env.name end save! if save end |
#add_environment(environment, save = true) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/canals/repository.rb', line 53 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.to_sym] = environment.to_hash save! if save end |
#delete(name, save = true) ⇒ Object
38 39 40 41 |
# File 'lib/canals/repository.rb', line 38 def delete(name, save=true) @repo[TUNNELS].delete(name) save! if save end |
#each(&block) ⇒ Object
22 23 24 |
# File 'lib/canals/repository.rb', line 22 def each(&block) @repo[TUNNELS].map{ |n, r| Canals::CanalOptions.new(r) }.each(&block) end |
#empty? ⇒ Boolean
26 27 28 |
# File 'lib/canals/repository.rb', line 26 def empty? @repo[TUNNELS].empty? end |
#environment(name = nil) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/canals/repository.rb', line 69 def environment(name=nil) if name.nil? args = @repo[ENVIRONMENTS].select{ |n,e| e[:default] }.values[0] else args = @repo[ENVIRONMENTS][name.to_sym] end Canals::Environment.new(args) if !args.nil? end |
#environments ⇒ Object
78 79 80 |
# File 'lib/canals/repository.rb', line 78 def environments @repo[ENVIRONMENTS].map { |n, e| Canals::Environment.new(e) } end |
#get(name) ⇒ Object
43 44 45 46 47 |
# File 'lib/canals/repository.rb', line 43 def get(name) name = name.to_sym return nil if !@repo[:tunnels].has_key? name CanalOptions.new(@repo[:tunnels][name]) end |
#has?(name) ⇒ Boolean
49 50 51 |
# File 'lib/canals/repository.rb', line 49 def has?(name) return @repo[:tunnels].has_key? name.to_sym end |