Class: Pow::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/pow/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile_path = :default) ⇒ Profile

Returns a new instance of Profile.



10
11
12
13
14
# File 'lib/pow/profile.rb', line 10

def initialize(profile_path=:default)
  @profile_path = (profile_path == :default) ? File.expand_path("~/.pow_defaults") : profile_path
  @settings     = read if File.exists?(@profile_path)
  @name         = "Default"
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#profile_pathObject

Returns the value of attribute profile_path.



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

def profile_path
  @profile_path
end

#settingsObject

Returns the value of attribute settings.



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

def settings
  @settings
end

#yamlObject (readonly)

Returns the value of attribute yaml.



8
9
10
# File 'lib/pow/profile.rb', line 8

def yaml
  @yaml
end

Instance Method Details

#inspectObject



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

def inspect
  "<Pow::Profile '#{name}'>"
end

#previewObject



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

def preview
  opts = {:text => "Hello world!"}.merge( settings )
  Puts.new( opts ).out!
end

#readObject



23
24
25
# File 'lib/pow/profile.rb', line 23

def read
  @yaml = YAML.load_file( profile_path )
end

#writeObject Also known as: save



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

def write
  FileUtils.mkdir_p( File.dirname(profile_path) )
  File.open( profile_path, 'wb'){|f| YAML.dump( settings, f ) }
  read
end