Class: Hubtime::HubConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/hubtime/hub_config.rb

Defined Under Namespace

Classes: Stuff

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHubConfig

Returns a new instance of HubConfig.



45
46
47
48
49
50
51
# File 'lib/hubtime/hub_config.rb', line 45

def initialize
  @file_name = "config"
  hash = read_file
  @user = hash["user"]
  @password = Stuff.decrypt(hash["password"])
  @ignore = hash["ignore"] || []
end

Instance Attribute Details

#ignoreObject (readonly)

Returns the value of attribute ignore.



44
45
46
# File 'lib/hubtime/hub_config.rb', line 44

def ignore
  @ignore
end

#passwordObject (readonly)

Returns the value of attribute password.



44
45
46
# File 'lib/hubtime/hub_config.rb', line 44

def password
  @password
end

#userObject (readonly)

Returns the value of attribute user.



44
45
46
# File 'lib/hubtime/hub_config.rb', line 44

def user
  @user
end

Class Method Details

.add_ignore(repo_name) ⇒ Object



36
37
38
# File 'lib/hubtime/hub_config.rb', line 36

def self.add_ignore(repo_name)
  instance.add_ignore(repo_name)
end

.auth(user, password) ⇒ Object



12
13
14
# File 'lib/hubtime/hub_config.rb', line 12

def self.auth(user, password)
  store(user, password)
end

.display_passwordObject



28
29
30
# File 'lib/hubtime/hub_config.rb', line 28

def self.display_password
  '*' * password.size
end

.ignoreObject



32
33
34
# File 'lib/hubtime/hub_config.rb', line 32

def self.ignore
  instance.ignore
end

.instanceObject



8
9
10
# File 'lib/hubtime/hub_config.rb', line 8

def self.instance
  @config ||= HubConfig.new
end

.passwordObject



24
25
26
# File 'lib/hubtime/hub_config.rb', line 24

def self.password
  instance.password
end

.store(user, password) ⇒ Object



16
17
18
# File 'lib/hubtime/hub_config.rb', line 16

def self.store(user, password)
  instance.store(user, password)
end

.threadsObject



40
41
42
# File 'lib/hubtime/hub_config.rb', line 40

def self.threads
  8
end

.userObject



20
21
22
# File 'lib/hubtime/hub_config.rb', line 20

def self.user
  instance.user
end

Instance Method Details

#add_ignore(repo_name) ⇒ Object



81
82
83
84
85
# File 'lib/hubtime/hub_config.rb', line 81

def add_ignore(repo_name)
  @ignore << repo_name
  @ignore.uniq!
  write_file!
end

#fileObject



70
71
72
73
74
75
76
77
78
79
# File 'lib/hubtime/hub_config.rb', line 70

def file
  file = File.join(File.expand_path("."), "hubtime_config.yml")

  unless File.exists?(file)
    File.open(file, 'w' ) do |out|
      YAML.dump({}, out )
    end
  end
  file
end

#read_fileObject



53
54
55
# File 'lib/hubtime/hub_config.rb', line 53

def read_file
  YAML.load_file(file)
end

#store(user, password) ⇒ Object



87
88
89
90
91
# File 'lib/hubtime/hub_config.rb', line 87

def store(user, password)
  @user = user
  @password = password
  write_file!
end

#write_file!Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hubtime/hub_config.rb', line 57

def write_file!
  hash = {}
  ["user", "password", "ignore"].each do |key|
    hash[key] = instance_variable_get("@#{key}")
  end

  hash["password"] = Stuff.encrypt(hash["password"])

  File.open(file, 'w' ) do |out|
    YAML.dump(hash, out)
  end
end