id3tag 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03c00ecdfdd2c6e53e5664831502753b5210a67098223bcfdb2805b9ab7958cd
4
- data.tar.gz: aba76b6019b3be742ddd51a2a024b90fefc59dfd1f645589f5f4a18b4da0dc60
3
+ metadata.gz: 622d36527a37667a879b10d57e1375687d961461c51fe9bdd57637f8911b797d
4
+ data.tar.gz: 0a10600c4a862998e60334795481c839814637a2d34a32e387245d7c5648cddb
5
5
  SHA512:
6
- metadata.gz: 85af215ef04e69deac371b5e9dea9c1bf401f01763794ae3f319be55ce09b6aa7fd67228fca0d62bfd956d4e8a445d173d985eecd4177462fa0b7a8aeae6aa3e
7
- data.tar.gz: d3fdb4e68b97b3dfffb013d544b6feeeb56b1d9277d5ec6407fa3327837e1e8b5148c849e419ab0b18bccd8b003e5e2d01b0cca437a6216b8c3f55b88634d559
6
+ metadata.gz: 681cea3d65d268544530e47096994732ebcc533a476e7bc843f50d6ad18eb7f77e4b7a81cc012a36f49cd063176a2a2cd37f77193c32eeb4e69e03fa8b511749
7
+ data.tar.gz: a7aea6358d52bca1d416cafeafdca93a797df5f91273528961a22b0658b46e6f9c0684806dbdbc22757961ab3012fe8bf7731bdab804e57bd2a2a3521fc0b09d
data/README.md CHANGED
@@ -60,9 +60,9 @@ You can inspect tag by calling `frame_ids` to see available frame ids or `frames
60
60
 
61
61
  ## Configuration
62
62
 
63
- It is also possible to provide configuration and overwrite default behaviour.
64
-
63
+
65
64
  ```ruby
65
+ # Configuration could be set using a block syntax.
66
66
  ID3Tag.configuration do |c|
67
67
 
68
68
  # This way you can avoid Encoding::InvalidByteSequenceError when tag contains invalid data.
@@ -76,6 +76,29 @@ ID3Tag.configuration do |c|
76
76
  c.v2_tag_read_limit = 1048576 # 1 megabyte
77
77
 
78
78
  end
79
+
80
+ ID3Tag.configuration.v2_tag_read_limit # 1048576
81
+
82
+ ID3Tag.configuration.v2_tag_read_limit = 1024
83
+
84
+ ID3Tag.configuration.v2_tag_read_limit # 1024
85
+
86
+
87
+ # In case you would like to set configuration temporally you could use `local_configuration` method.
88
+ # Within this block you can read and modify configuration and it wont affect global or layers above.
89
+
90
+ ID3Tag.local_configuration do
91
+ ID3Tag.configuration.v2_tag_read_limit # 1024
92
+ ID3Tag.configuration.v2_tag_read_limit = 9999
93
+ # ...
94
+ ID3Tag.configuration.v2_tag_read_limit # 9999
95
+ end
96
+
97
+ ID3Tag.configuration.v2_tag_read_limit # 1024
98
+
99
+ ID3Tag.reset_configuration # Resets global configuration to defaults
100
+
101
+ ID3Tag.configuration.v2_tag_read_limit # 0
79
102
  ```
80
103
 
81
104
 
@@ -1,4 +1,6 @@
1
1
  require "stringio"
2
+ require "singleton"
3
+ require "id3tag/configuration_struct"
2
4
  require "id3tag/configuration"
3
5
  require "id3tag/synchsafe_integer"
4
6
  require "id3tag/audio_file"
@@ -42,15 +44,16 @@ module ID3Tag
42
44
  end
43
45
 
44
46
  class << self
45
- def configuration
46
- @configuration ||= reset_configuration
47
- yield @configuration if block_given?
48
- @configuration
47
+ def configuration(&blk)
48
+ ID3Tag::Configuration.configuration(&blk)
49
49
  end
50
50
 
51
- def reset_configuration(configuration = ID3Tag::Configuration.new)
52
- raise ArgumentError, "Passed argument must be a ID3Tag::Configuration class object" unless configuration.is_a?(ID3Tag::Configuration)
53
- @configuration = configuration
51
+ def local_configuration(&blk)
52
+ ID3Tag::Configuration.local_configuration(&blk)
53
+ end
54
+
55
+ def reset_configuration
56
+ ID3Tag::Configuration.reset
54
57
  end
55
58
  end
56
59
  end
@@ -1,11 +1,46 @@
1
1
  module ID3Tag
2
2
  class Configuration
3
+ ResetError = Class.new(StandardError)
4
+ include Singleton
5
+ StackItem = Struct.new(:configuration)
6
+
7
+ class << self
8
+ def local_configuration(&blk)
9
+ instance.send(:local_configuration, &blk)
10
+ end
11
+
12
+ def configuration
13
+ value = instance.instance_variable_get(:@stack).last&.configuration || instance.instance_variable_get(:@global_configuration)
14
+ yield value if block_given?
15
+ value
16
+ end
17
+
18
+ def reset
19
+ instance.send(:reset)
20
+ end
21
+ end
22
+
23
+ def local_configuration
24
+ stack_item = StackItem.new((@stack.last&.configuration || @global_configuration).dup)
25
+ stack_backup = @stack.dup
26
+ @stack << stack_item
27
+ begin
28
+ yield stack_item.configuration
29
+ ensure
30
+ @stack.replace stack_backup
31
+ end
32
+ end
33
+
34
+ private
35
+
3
36
  def initialize
4
- @string_encode_options = {}
5
- @v2_tag_read_limit = 0
37
+ @stack = []
38
+ reset
6
39
  end
7
40
 
8
- attr_accessor :string_encode_options
9
- attr_accessor :v2_tag_read_limit
41
+ def reset
42
+ raise ResetError, "Configuration cannot be reset within local_configuration block" if @stack.size > 0
43
+ @global_configuration = ConfigurationStruct.new
44
+ end
10
45
  end
11
46
  end
@@ -0,0 +1,11 @@
1
+ module ID3Tag
2
+ class ConfigurationStruct
3
+ def initialize
4
+ @string_encode_options = {}
5
+ @v2_tag_read_limit = 0
6
+ end
7
+
8
+ attr_accessor :string_encode_options
9
+ attr_accessor :v2_tag_read_limit
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ID3Tag
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id3tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krists Ozols
@@ -122,6 +122,7 @@ files:
122
122
  - lib/id3tag.rb
123
123
  - lib/id3tag/audio_file.rb
124
124
  - lib/id3tag/configuration.rb
125
+ - lib/id3tag/configuration_struct.rb
125
126
  - lib/id3tag/encoding_util.rb
126
127
  - lib/id3tag/frame_id_advisor.rb
127
128
  - lib/id3tag/frames/util/genre_names.rb