Class: ConfCtl::Swpins::Specs::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/swpins/specs/base.rb

Direct Known Subclasses

Directory, Git

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, nix_opts, json_opts) ⇒ Base

Returns a new instance of Base.

Parameters:

  • name (String)
  • nix_opts (Hash)

    options from the user’s nix configuration

  • json_opts (Hash)

    options from generated json file



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/confctl/swpins/specs/base.rb', line 29

def initialize(name, nix_opts, json_opts)
  @name = name
  @nix_opts = nix_opts
  @json_opts = json_opts
  @state = nil
  @info = nil
  @fetcher = nil
  @fetcher_opts = nil
  @errors = []
  parse
end

Class Attribute Details

.typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/confctl/swpins/specs/base.rb', line 4

def type
  @type
end

Instance Attribute Details

#channelString?

Parameters:

  • (String)

Returns:

  • (String, nil)


18
19
20
# File 'lib/confctl/swpins/specs/base.rb', line 18

def channel
  @channel
end

#errorsArray (readonly)

Returns:

  • (Array)


21
22
23
# File 'lib/confctl/swpins/specs/base.rb', line 21

def errors
  @errors
end

#infoHash

Returns:

  • (Hash)


24
25
26
# File 'lib/confctl/swpins/specs/base.rb', line 24

def info
  @info
end

#nameString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/confctl/swpins/specs/base.rb', line 14

def name
  @name
end

Class Method Details

.handle(name) ⇒ Object

Parameters:

  • name (Symbol)


7
8
9
10
# File 'lib/confctl/swpins/specs/base.rb', line 7

def handle(name)
  @type = name
  Swpins::Spec.register(name, self)
end

Instance Method Details

#as_jsonObject



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/confctl/swpins/specs/base.rb', line 119

def as_json
  ret = {}
  ret['type'] = type.to_s
  ret['nix_options'] = nix_opts
  ret['state'] = state
  ret['info'] = info
  ret['fetcher'] = fetcher && {
    'type' => fetcher,
    'options' => fetcher_opts
  }
  ret
end

#auto_update?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/confctl/swpins/specs/base.rb', line 59

def auto_update?
  can_update? && nix_opts['update']['auto']
end

#can_update?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/confctl/swpins/specs/base.rb', line 55

def can_update?
  nix_opts['update']['ref'] ? true : false
end

#check_info(other_info) ⇒ Boolean

Check that ‘other_info` corresponds to this spec

Parameters:

  • other_info (Hash)

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


86
87
88
# File 'lib/confctl/swpins/specs/base.rb', line 86

def check_info(other_info)
  raise NotImplementedError
end

#check_optsBoolean

Check that current nix options match those that generated json options

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/confctl/swpins/specs/base.rb', line 47

def check_opts
  raise NotImplementedError
end

#from_channel?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/confctl/swpins/specs/base.rb', line 63

def from_channel?
  !channel.nil?
end

#prefetch_set(args) ⇒ Object

Raises:

  • (NotImplementedError)


75
76
77
# File 'lib/confctl/swpins/specs/base.rb', line 75

def prefetch_set(args)
  raise NotImplementedError
end

#prefetch_updateObject

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/confctl/swpins/specs/base.rb', line 79

def prefetch_update
  raise NotImplementedError
end

#statusObject



67
68
69
# File 'lib/confctl/swpins/specs/base.rb', line 67

def status
  valid? ? version : 'update'
end

#string_changelog_info(type, other_info, **opts) ⇒ String?

Generate changelog between revisions

Parameters:

  • type (:upgrade, :downgrade)
  • other_info (any)

    version reference

  • opts (Hash)

    options

Options Hash (**opts):

  • :color (Boolean)
  • :verbose (Boolean)
  • :patch (Boolean)

Returns:

  • (String, nil)

Raises:

  • (NotImplementedError)


105
106
107
# File 'lib/confctl/swpins/specs/base.rb', line 105

def string_changelog_info(type, other_info, **opts)
  raise NotImplementedError
end

#string_diff_info(type, other_info, **opts) ⇒ String?

Generate diff between revisions

Parameters:

  • type (:upgrade, :downgrade)
  • other_info (any)

    version reference

  • opts (Hash)

    options

Options Hash (**opts):

  • :color (Boolean)

Returns:

  • (String, nil)

Raises:

  • (NotImplementedError)


115
116
117
# File 'lib/confctl/swpins/specs/base.rb', line 115

def string_diff_info(type, other_info, **opts)
  raise NotImplementedError
end

#to_json(*args) ⇒ Object



132
133
134
# File 'lib/confctl/swpins/specs/base.rb', line 132

def to_json(*args)
  as_json.to_json(*args)
end

#typeObject



41
42
43
# File 'lib/confctl/swpins/specs/base.rb', line 41

def type
  self.class.type
end

#valid?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/confctl/swpins/specs/base.rb', line 51

def valid?
  errors.empty?
end

#versionObject

Raises:

  • (NotImplementedError)


71
72
73
# File 'lib/confctl/swpins/specs/base.rb', line 71

def version
  raise NotImplementedError
end

#version_info(other_info) ⇒ String

Return version based on the info hash

Parameters:

  • other_info (Hash)

Returns:

  • (String)

Raises:

  • (NotImplementedError)


93
94
95
# File 'lib/confctl/swpins/specs/base.rb', line 93

def version_info(other_info)
  raise NotImplementedError
end