Class: Gitscrub::Profile

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

Constant Summary collapse

PROFILE_FILE =
".profile.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Profile

Returns a new instance of Profile.



29
30
31
# File 'lib/gitscrub/profile.rb', line 29

def initialize(settings)
  @settings = settings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/gitscrub/profile.rb', line 20

def method_missing(method, *args, &block)
  if method.to_s.end_with?("=")
    method = method.to_s.chop.to_sym
    return settings[method] = args[0] if settings.include?(method)
  end
  return(settings[method]) if settings.include?(method)
  super
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



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

def settings
  @settings
end

Class Method Details

.loadObject



9
10
11
12
13
14
15
16
# File 'lib/gitscrub/profile.rb', line 9

def load
  settings = {
    :level => 0
  }

  settings.merge! YAML::load(File.open(PROFILE_FILE)) if File.exists?(PROFILE_FILE)
  self.new(settings)
end

Instance Method Details

#saveObject



33
34
35
36
37
# File 'lib/gitscrub/profile.rb', line 33

def save
  File.open(PROFILE_FILE, 'w') do |out|
    YAML.dump(settings, out)
  end
end