Class: RestrictedOrderedHash
- Inherits:
-
ActiveSupport::OrderedHash
- Object
- ActiveSupport::OrderedHash
- RestrictedOrderedHash
- Defined in:
- lib/helpers/restricted_ordered_hash.rb
Overview
Class RestrictedOrderedHash
this is a helper Class for ID3::Frame
this is a helper Class for GenericTag
this is from 2002 .. new Ruby Versions now have "OrderedHash" .. but I'll keep this class for now.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#locked ⇒ Object
Returns the value of attribute locked.
Instance Method Summary collapse
- #[]=(key, val) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize ⇒ RestrictedOrderedHash
constructor
A new instance of RestrictedOrderedHash.
- #lock ⇒ Object
-
#old_delete ⇒ Object
users can not delete entries from a locked hash..
- #old_store ⇒ Object
Constructor Details
#initialize ⇒ RestrictedOrderedHash
Returns a new instance of RestrictedOrderedHash.
19 20 21 22 |
# File 'lib/helpers/restricted_ordered_hash.rb', line 19 def initialize @locked = false super end |
Instance Attribute Details
#locked ⇒ Object
Returns the value of attribute locked.
13 14 15 |
# File 'lib/helpers/restricted_ordered_hash.rb', line 13 def locked @locked end |
Instance Method Details
#[]=(key, val) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/helpers/restricted_ordered_hash.rb', line 26 def []= (key,val) if self[key] # self.old_store(key,val) # this would overwrite the old_value if a key already exists (duplicate ID3-Frames) # strictly speaking, we only need this for the ID3v2 Tag class Tag2: if self[key].class != ID3::FrameArray # Make this ID3::FrameArray < Array old_value = self[key] new_value = ID3::FrameArray.new new_value << old_value # make old_value a FrameArray self.old_store(key, new_value ) end self[key] << val else if @locked # we're not allowed to add new keys! raise ArgumentError, "You can not add new keys! The ID3-frame #{@name} has fixed entries!\n" + " valid key are: " + self.keys.join(",") +"\n" else self.old_store(key,val) end end end |
#delete(key) ⇒ Object
54 55 56 57 58 |
# File 'lib/helpers/restricted_ordered_hash.rb', line 54 def delete(key) if !@locked old_delete(key) end end |
#lock ⇒ Object
15 16 17 |
# File 'lib/helpers/restricted_ordered_hash.rb', line 15 def lock @locked = true end |
#old_delete ⇒ Object
users can not delete entries from a locked hash..
52 |
# File 'lib/helpers/restricted_ordered_hash.rb', line 52 alias old_delete delete |
#old_store ⇒ Object
24 |
# File 'lib/helpers/restricted_ordered_hash.rb', line 24 alias old_store []= |