Class: Gcloud::Datastore::Properties
- Inherits:
-
Object
- Object
- Gcloud::Datastore::Properties
- Defined in:
- lib/gcloud/datastore/properties.rb
Overview
Properties
Instance Method Summary collapse
- #[](key) ⇒ Object (also: #read)
- #[]=(key, value) ⇒ Object (also: #write)
- #delete(key, &block) ⇒ Object
- #each(&block) ⇒ Object
- #exist?(key) ⇒ Boolean
- #fetch(key, &_block) ⇒ Object
-
#initialize(properties = {}) ⇒ Properties
constructor
A new instance of Properties.
- #to_h ⇒ Object (also: #to_hash)
Constructor Details
#initialize(properties = {}) ⇒ Properties
Returns a new instance of Properties.
20 21 22 23 24 25 26 27 |
# File 'lib/gcloud/datastore/properties.rb', line 20 def initialize properties = {} @hash = {} properties.each do |key, value| key = ensure_key_type key value = ensure_value_type value @hash[key] = value end end |
Instance Method Details
#[](key) ⇒ Object Also known as: read
29 30 31 32 |
# File 'lib/gcloud/datastore/properties.rb', line 29 def [] key key = ensure_key_type key @hash[key] end |
#[]=(key, value) ⇒ Object Also known as: write
35 36 37 38 39 |
# File 'lib/gcloud/datastore/properties.rb', line 35 def []= key, value key = ensure_key_type key value = ensure_value_type value @hash[key] = value end |
#delete(key, &block) ⇒ Object
57 58 59 60 |
# File 'lib/gcloud/datastore/properties.rb', line 57 def delete key, &block key = ensure_key_type key @hash.delete key, &block end |
#each(&block) ⇒ Object
53 54 55 |
# File 'lib/gcloud/datastore/properties.rb', line 53 def each &block @hash.each(&block) end |
#exist?(key) ⇒ Boolean
42 43 44 45 |
# File 'lib/gcloud/datastore/properties.rb', line 42 def exist? key key = ensure_key_type key @hash.key? key end |
#fetch(key, &_block) ⇒ Object
47 48 49 50 51 |
# File 'lib/gcloud/datastore/properties.rb', line 47 def fetch key, &_block key = ensure_key_type key @hash[key] = yield unless exist? key @hash[key] end |
#to_h ⇒ Object Also known as: to_hash
62 63 64 |
# File 'lib/gcloud/datastore/properties.rb', line 62 def to_h @hash.dup end |