Class: OsCtld::Repository

Inherits:
Object
  • Object
show all
Includes:
Assets::Definition, Lockable, Manipulable
Defined in:
lib/osctld/repository.rb

Defined Under Namespace

Classes: Template

Constant Summary collapse

USER =
'repository'
UID =
Etc.getpwnam(USER).uid

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assets::Definition

#define_assets

Methods included from Manipulable

#acquire_manipulation_lock, #init_manipulable, #is_being_manipulated?, #manipulate, #manipulated_by, #release_manipulation_lock

Methods included from Lockable

#exclusively, included, #inclusively, #init_lock, #lock, #unlock

Constructor Details

#initialize(pool, name, load: true) ⇒ Repository

Returns a new instance of Repository



18
19
20
21
22
23
24
25
26
# File 'lib/osctld/repository.rb', line 18

def initialize(pool, name, load: true)
  init_lock
  init_manipulable
  @pool = pool
  @name = name
  @enabled = true
  @attrs = Attributes.new
  load_config if load
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs



16
17
18
# File 'lib/osctld/repository.rb', line 16

def attrs
  @attrs
end

#nameObject (readonly)

Returns the value of attribute name



16
17
18
# File 'lib/osctld/repository.rb', line 16

def name
  @name
end

#poolObject (readonly)

Returns the value of attribute pool



16
17
18
# File 'lib/osctld/repository.rb', line 16

def pool
  @pool
end

#stateObject (readonly, protected)

Returns the value of attribute state



119
120
121
# File 'lib/osctld/repository.rb', line 119

def state
  @state
end

#urlObject (readonly)

Returns the value of attribute url



16
17
18
# File 'lib/osctld/repository.rb', line 16

def url
  @url
end

Instance Method Details

#assetsObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/osctld/repository.rb', line 37

def assets
  define_assets do |add|
    add.directory(
      cache_path,
      desc: 'Local cache',
      user: UID,
      group: 0,
      mode: 0700
    )
  end
end

#cache_pathObject



110
111
112
# File 'lib/osctld/repository.rb', line 110

def cache_path
  File.join(pool.repo_path, name)
end

#config_pathObject



106
107
108
# File 'lib/osctld/repository.rb', line 106

def config_path
  File.join(pool.conf_path, 'repository', "#{name}.yml")
end

#configure(url) ⇒ Object



32
33
34
35
# File 'lib/osctld/repository.rb', line 32

def configure(url)
  @url = url
  save_config
end

#disableObject



62
63
64
65
# File 'lib/osctld/repository.rb', line 62

def disable
  @enabled = false
  save_config
end

#disabled?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/osctld/repository.rb', line 53

def disabled?
  !enabled?
end

#enableObject



57
58
59
60
# File 'lib/osctld/repository.rb', line 57

def enable
  @enabled = true
  save_config
end

#enabled?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/osctld/repository.rb', line 49

def enabled?
  @enabled
end

#idObject



28
29
30
# File 'lib/osctld/repository.rb', line 28

def id
  name
end

#load_configObject (protected)



121
122
123
124
125
126
127
# File 'lib/osctld/repository.rb', line 121

def load_config
  cfg = YAML.load_file(config_path)

  @url = cfg['url']
  @enabled = cfg['enabled']
  @attrs = Attributes.load(cfg['attrs'] || {})
end

#manipulation_resourceObject



114
115
116
# File 'lib/osctld/repository.rb', line 114

def manipulation_resource
  ['repository', "#{pool.name}:#{name}"]
end

#save_configObject (protected)



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/osctld/repository.rb', line 129

def save_config
  File.open(config_path, 'w', 0400) do |f|
    f.write(YAML.dump({
      'url' => url,
      'enabled' => enabled?,
      'attrs' => attrs.dump,
    }))
  end

  File.chown(0, 0, config_path)
end

#set(opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :attrs (Hash)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/osctld/repository.rb', line 69

def set(opts)
  opts.each do |k, v|
    case k
    when :url
      @url = v

    when :attrs
      attrs.update(v)

    else
      fail "unsupported option '#{k}'"
    end
  end

  save_config
end

#templatesObject



102
103
104
# File 'lib/osctld/repository.rb', line 102

def templates
  # TODO
end

#unset(opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :attrs (Array<String>)


88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/osctld/repository.rb', line 88

def unset(opts)
  opts.each do |k, v|
    case k
    when :attrs
      v.each { |attr| attrs.unset(attr) }

    else
      fail "unsupported option '#{k}'"
    end
  end

  save_config
end