Class: Bog::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/bog/profile.rb,
lib/bog/profile/exception.rb

Defined Under Namespace

Classes: Exception

Constant Summary collapse

UNWANTED_ENTRIES =
%w( . .. )

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Profile

Returns a new instance of Profile.



11
12
13
14
15
# File 'lib/bog/profile.rb', line 11

def initialize(options)
  @configurations = options[:configurations]
  @profile_name = options[:profile_name]
  @path = options[:path]
end

Instance Attribute Details

#configurationsObject

Returns the value of attribute configurations.



6
7
8
# File 'lib/bog/profile.rb', line 6

def configurations
  @configurations
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/bog/profile.rb', line 7

def path
  @path
end

#profile_nameObject (readonly)

Returns the value of attribute profile_name.



7
8
9
# File 'lib/bog/profile.rb', line 7

def profile_name
  @profile_name
end

Class Method Details

.find(profile) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/bog/profile.rb', line 22

def self.find(profile)
  if Dir.entries(File.expand_path('~/.bog/profiles')).include?(profile.to_s)
    return Bog::Profile.load(profile)
  else
  raise Bog::Profile::Exception::ProfileNotFound
  end
end

.load(profile) ⇒ Object



30
31
32
33
# File 'lib/bog/profile.rb', line 30

def self.load(profile)
  configurations = Dir.entries(profile_root(profile)).delete_if {|e| Bog::Profile::UNWANTED_ENTRIES.include?(e)}
  return Bog::Profile.new({:configurations => configurations, :profile_name => profile, :path => profile_root(profile)})
end

.switch_to(profile) ⇒ Object



17
18
19
20
# File 'lib/bog/profile.rb', line 17

def self.switch_to(profile)
  target_profile = self.find(profile)
  target_profile.make_current
end

Instance Method Details

#make_currentObject



35
36
37
38
# File 'lib/bog/profile.rb', line 35

def make_current
  current_status_file = File.expand_path('~/.bog/current')
  symlink(profile_root, current_status_file,)
end