thinp_xml 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTA2MWY0ZGYyYWVlYTc2ZGRmMzM4ZTE2Y2FjNGZlZmM1NDliOWRlMA==
4
+ ZjQzMTBjOTBhM2VlZjZkMGIxODgxMzk3ZGIwZWE0ZWNkNGQ2ZTM1MQ==
5
5
  data.tar.gz: !binary |-
6
- MDk1MDhkMjFiZmI5MzY0NGQxOWJhYTBjNTgyNjFmYzhmY2U3MTA3Nw==
6
+ ZGU4NjE1ZDA1Yjc2ZGU5ZGU3MTM1ZDJkYjgxOGI0ZGYxMjhlMzZhOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDMzZTdiZWU5ZTA3NmU5YzJlYzYxZjkyY2E4OTEyZTE0YjA2ZmFiZjg1ZmI3
10
- OGNkNmEzOTdjMjhlZDE2NjdjYTBkNzE2MTI0YzI3MmUxMDgxNGRjODcxZjFj
11
- ZTk4M2JmZTg5ODhiNmMwZmMxOGRhMGU3OWVjMTg4Yzg4YTQ3NjE=
9
+ YjVkMjliNDYzZjViZmNmMzk0NDM4MmQ4MWUwYzg1M2M3N2NlMGJjNDQ4ZGU5
10
+ YjMwYjAyM2I1MTg3MjgxZmI2MWRhNjc2ZmRkZmJjZGUyNjNlMGY5NjUzMDY0
11
+ ODQxY2I3MTY1ZGM1ZWI2NGNhNGU3OGI3NTRiYzI5ODFkYjIzNmE=
12
12
  data.tar.gz: !binary |-
13
- OWUyNGVkZTNhNzQ1MDEzMjQ3ZWI4MGYxZmQzNTY5YjZkN2ZkZDE1NDMzMWMy
14
- YzIxYWMxMjMwZDQxZjQ2M2QxNDQwMDY2Y2E5MTAzZjFjZDkxMjJkZjVhY2E4
15
- OGU4NGU4ZWJmN2E3MDgwMjI0OTUxNmMxNDlhNWRiMmJhZjRjYzU=
13
+ YzQ4MjYyNjA4MmIwNTY0OTk2OGY0NTExMmU5MmY2Y2UxOGY0NmZkMjdmNjU4
14
+ ZTdkOTRjYzljMjAxNWY2ZGJkZDk1MDk4NWNkMjBhODhhMzg2ZjBkNzA4ZmNk
15
+ NmQ5MjY5ZjNlMjY0NjNhMWIyYjA1MjM1MTEyMmVhNzU1YjEwOTA=
@@ -45,9 +45,11 @@ Feature: I can create new metadata
45
45
  Then the stdout should contain:
46
46
  """
47
47
  <superblock uuid="" block_size="128" nr_cache_blocks="3" policy="mq" hint_width="4">
48
- <mapping cache_block="0" origin_block="0" dirty="false"/>
49
- <mapping cache_block="1" origin_block="1" dirty="false"/>
50
- <mapping cache_block="2" origin_block="2" dirty="false"/>
48
+ <mappings>
49
+ <mapping cache_block="0" origin_block="0" dirty="false"/>
50
+ <mapping cache_block="1" origin_block="1" dirty="false"/>
51
+ <mapping cache_block="2" origin_block="2" dirty="false"/>
52
+ </mappings>
51
53
  </superblock>
52
54
  """
53
55
 
@@ -56,9 +58,11 @@ Feature: I can create new metadata
56
58
  Then the stdout should contain:
57
59
  """
58
60
  <superblock uuid="" block_size="128" nr_cache_blocks="3" policy="mq" hint_width="4">
59
- <mapping cache_block="0" origin_block="0" dirty="true"/>
60
- <mapping cache_block="1" origin_block="1" dirty="true"/>
61
- <mapping cache_block="2" origin_block="2" dirty="true"/>
61
+ <mappings>
62
+ <mapping cache_block="0" origin_block="0" dirty="true"/>
63
+ <mapping cache_block="1" origin_block="1" dirty="true"/>
64
+ <mapping cache_block="2" origin_block="2" dirty="true"/>
65
+ </mappings>
62
66
  </superblock>
63
67
  """
64
68
 
@@ -67,9 +71,11 @@ Feature: I can create new metadata
67
71
  Then the stdout should contain:
68
72
  """
69
73
  <superblock uuid="" block_size="128" nr_cache_blocks="3" policy="fred" hint_width="4">
70
- <mapping cache_block="0" origin_block="0" dirty="false"/>
71
- <mapping cache_block="1" origin_block="1" dirty="false"/>
72
- <mapping cache_block="2" origin_block="2" dirty="false"/>
74
+ <mappings>
75
+ <mapping cache_block="0" origin_block="0" dirty="false"/>
76
+ <mapping cache_block="1" origin_block="1" dirty="false"/>
77
+ <mapping cache_block="2" origin_block="2" dirty="false"/>
78
+ </mappings>
73
79
  </superblock>
74
80
  """
75
81
 
@@ -78,8 +84,10 @@ Feature: I can create new metadata
78
84
  Then the stdout should contain:
79
85
  """
80
86
  <superblock uuid="" block_size="128" nr_cache_blocks="3" policy="mq" hint_width="8">
81
- <mapping cache_block="0" origin_block="0" dirty="false"/>
82
- <mapping cache_block="1" origin_block="1" dirty="false"/>
83
- <mapping cache_block="2" origin_block="2" dirty="false"/>
87
+ <mappings>
88
+ <mapping cache_block="0" origin_block="0" dirty="false"/>
89
+ <mapping cache_block="1" origin_block="1" dirty="false"/>
90
+ <mapping cache_block="2" origin_block="2" dirty="false"/>
91
+ </mappings>
84
92
  </superblock>
85
93
  """
@@ -14,6 +14,31 @@ module CacheXML
14
14
  @e.emit_tag(sb, 'superblock', :uuid, :block_size, :nr_cache_blocks, :policy, :hint_width, &block)
15
15
  end
16
16
 
17
+ def emit_mappings(ms)
18
+ return if no_entries(ms)
19
+
20
+ block = lambda do
21
+ ms.each {|m| emit_mapping(m)}
22
+ end
23
+
24
+ @e.emit_tag(ms, 'mappings', &block)
25
+ end
26
+
27
+ def emit_hints(hs)
28
+ return if no_entries(hs)
29
+
30
+ block = lambda do
31
+ hs.each {|h| emit_hint(h)}
32
+ end
33
+
34
+ @e.emit_tag(hs, 'hints', &block)
35
+ end
36
+
37
+ private
38
+ def no_entries(a)
39
+ a.nil? || a.size == 0
40
+ end
41
+
17
42
  def emit_mapping(m)
18
43
  @e.emit_tag(m, 'mapping', :cache_block, :origin_block, :dirty)
19
44
  end
@@ -29,13 +54,8 @@ module CacheXML
29
54
  def write_xml(metadata, io)
30
55
  e = CacheEmitterDetail::CacheEmitter.new(io)
31
56
  e.emit_superblock(metadata.superblock) do
32
- metadata.mappings.each do |m|
33
- e.emit_mapping(m)
34
- end
35
-
36
- metadata.hints.each do |h|
37
- e.emit_hint(h)
38
- end
57
+ e.emit_mappings(metadata.mappings)
58
+ e.emit_hints(metadata.hints)
39
59
  end
40
60
  end
41
61
  end
@@ -11,9 +11,9 @@ module ThinpXML
11
11
  def emit_tag(obj, tag, *fields, &block)
12
12
  expanded = fields.map {|fld| "#{fld}=\"#{obj.send(fld)}\""}
13
13
  if block.nil?
14
- emit_line "<#{tag} #{expanded.join(' ')}/>"
14
+ emit_line "<#{tag}#{join_fields(expanded)}/>"
15
15
  else
16
- emit_line "<#{tag} #{expanded.join(' ')}>"
16
+ emit_line "<#{tag}#{join_fields(expanded)}>"
17
17
  push
18
18
  yield unless block.nil?
19
19
  pop
@@ -26,6 +26,11 @@ module ThinpXML
26
26
  end
27
27
 
28
28
  private
29
+
30
+ def join_fields(fields)
31
+ fields.size == 0 ? "" : " #{fields.join(' ')}"
32
+ end
33
+
29
34
  def push
30
35
  @indent += 2
31
36
  end
@@ -1,3 +1,3 @@
1
1
  module ThinpXml
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thinp_xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Thornber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-25 00:00:00.000000000 Z
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ejt_command_line