Class: Zammad::SZPM
- Inherits:
-
Object
- Object
- Zammad::SZPM
- Defined in:
- lib/zammad/szpm.rb,
lib/zammad/szpm/version.rb
Overview
Handles all SZPM and ZPM related stuff
Constant Summary collapse
- VERSION =
'0.2.3'
Instance Attribute Summary collapse
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
-
#szpm ⇒ Object
readonly
Returns the value of attribute szpm.
Instance Method Summary collapse
-
#add_build_information(build_host) ⇒ Hash
Adds the buildhost and builddate to the SZPM file.
-
#add_file(location, permission = 644) ⇒ Hash
Adds a new file to the filelist of the SZPM file.
-
#initialize(szpm_file) ⇒ SZPM, Hash
constructor
Creates an instance based on a given SZPM file path.
-
#parse ⇒ Hash
Parses the given SZPM file.
-
#store ⇒ Hash
Stores the changes to the SZPM file.
-
#version(version, change_log) ⇒ Hash
Adds a new version and the change_log to the SZPM file.
-
#zpm ⇒ String
Creates an ZPM string out of the SZPM file.
Constructor Details
#initialize(szpm_file) ⇒ SZPM, Hash
Creates an instance based on a given SZPM file path.
17 18 19 20 21 22 |
# File 'lib/zammad/szpm.rb', line 17 def initialize(szpm_file) @szpm_file = szpm_file parse end |
Instance Attribute Details
#structure ⇒ Object (readonly)
Returns the value of attribute structure.
11 12 13 |
# File 'lib/zammad/szpm.rb', line 11 def structure @structure end |
#szpm ⇒ Object (readonly)
Returns the value of attribute szpm.
10 11 12 |
# File 'lib/zammad/szpm.rb', line 10 def szpm @szpm end |
Instance Method Details
#add_build_information(build_host) ⇒ Hash
Adds the buildhost and builddate to the SZPM file.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/zammad/szpm.rb', line 58 def add_build_information(build_host) parse # add buildhost @structure['buildhost'] = build_host # add builddate @structure['builddate'] = Time.zone.now store end |
#add_file(location, permission = 644) ⇒ Hash
Adds a new file to the filelist of the SZPM file.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/zammad/szpm.rb', line 74 def add_file( location, = 644 ) parse update = true @structure['files'].each { |file| next if file['location'] != location next if file['permission'] != update = false break } return if !update @structure['files'].push({ 'location' => location, 'permission' => , }) store end |
#parse ⇒ Hash
Parses the given SZPM file.
112 113 114 115 116 117 118 119 |
# File 'lib/zammad/szpm.rb', line 112 def parse szpm_read_handle = File.open(@szpm_file) @szpm = szpm_read_handle.read szpm_read_handle.close @structure = JSON.parse( @szpm ) end |
#store ⇒ Hash
Stores the changes to the SZPM file.
100 101 102 103 104 105 106 107 |
# File 'lib/zammad/szpm.rb', line 100 def store File.open(@szpm_file, 'w') { |file| file.write( JSON.pretty_generate(@structure) ) } parse end |
#version(version, change_log) ⇒ Hash
Adds a new version and the change_log to the SZPM file.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zammad/szpm.rb', line 29 def version(version, change_log) parse # change version @structure['version'] = version # append change_log @structure['change_log'] ||= [] # remove tabs from change_log change_log.gsub!(/\t/, ' ') # strip whitespaces change_log.strip! # append entry @structure['change_log'].push({ 'version' => version, 'date' => Time.zone.now, 'content' => change_log }) store end |
#zpm ⇒ String
Creates an ZPM string out of the SZPM file.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/zammad/szpm.rb', line 124 def zpm zpm = parse folder = File.dirname(@szpm_file) zpm['files'].collect! { |file| file_location = file['location'] file_handle = File.open("#{folder}/#{file_location}", 'r') file_content = file_handle.read file_handle.close file['encode'] = 'base64' file['content'] = Base64.strict_encode64( file_content ) file } JSON.pretty_generate(zpm) end |