Class: ZdHire::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/zd_hire/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
# File 'lib/zd_hire/config.rb', line 8

def initialize
  if File.exist?(config_file)
    begin
      deserialize_from_file
    rescue
      FileUtils.rm(config_file)
    end
  end
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



6
7
8
# File 'lib/zd_hire/config.rb', line 6

def branch
  @branch
end

#github_tokenObject

Returns the value of attribute github_token.



6
7
8
# File 'lib/zd_hire/config.rb', line 6

def github_token
  @github_token
end

#local_pathObject

Returns the value of attribute local_path.



6
7
8
# File 'lib/zd_hire/config.rb', line 6

def local_path
  @local_path
end

#origin_repoObject

Returns the value of attribute origin_repo.



6
7
8
# File 'lib/zd_hire/config.rb', line 6

def origin_repo
  @origin_repo
end

Instance Method Details

#attributesObject



30
31
32
33
34
35
36
37
# File 'lib/zd_hire/config.rb', line 30

def attributes
  {
    github_token:   github_token,
    origin_repo:    origin_repo,
    local_path:     local_path,
    branch:         branch,
  }
end

#attributes=(options) ⇒ Object



43
44
45
46
47
48
# File 'lib/zd_hire/config.rb', line 43

def attributes=(options)
  self.github_token   = options[:github_token]
  self.origin_repo    = options[:origin_repo]
  self.local_path     = options[:local_path]
  self.branch         = options[:branch]
end

#config_fileObject



18
19
20
# File 'lib/zd_hire/config.rb', line 18

def config_file
  @config_file ||= File.join(File.expand_path('~'), '.zd_hire')
end

#deserialize_from_fileObject



22
23
24
# File 'lib/zd_hire/config.rb', line 22

def deserialize_from_file
  self.attributes = YAML.load_file(config_file)
end

#serialize_to_fileObject



26
27
28
# File 'lib/zd_hire/config.rb', line 26

def serialize_to_file
  File.write(config_file, attributes.to_yaml)
end

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/zd_hire/config.rb', line 39

def valid?
  attributes.values.none?(&:nil?)
end