Class: BitBucket::API::Config::PropertySet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bitbucket_rest_api/api/config/property_set.rb

Overview

Class responsible for storing configuration properties

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, properties = Set.new) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize an PropertySet

Parameters:

  • parent (Object) (defaults to: nil)
  • properties (Set) (defaults to: Set.new)


22
23
24
25
26
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 22

def initialize(parent = nil, properties = Set.new)
  @parent = parent
  @properties = properties
  @map = {}
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



10
11
12
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 10

def parent
  @parent
end

#propertiesObject (readonly)

Returns the value of attribute properties.



12
13
14
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 12

def properties
  @properties
end

Instance Method Details

#<<(property) ⇒ self

Adds property to the set

Examples:

properties_set << property

Parameters:

Returns:

  • (self)


53
54
55
56
57
58
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 53

def <<(property)
  properties << property
  update_map(property.name, property.default)
  property.define_accessor_methods(self)
  self
end

#[](name) ⇒ Object Also known as: fetch

Access property by name



63
64
65
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 63

def [](name)
  @map[name]
end

#[]=(name, property) ⇒ Object

Set property value by name



71
72
73
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 71

def []=(name, property)
  update_map(name, property)
end

#define_reader_method(property, method_name, visibility) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
104
105
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 101

def define_reader_method(property, method_name, visibility)
  property_set = self
  parent.send(:define_method, method_name) { property_set[property.name] }
  parent.send(visibility, method_name)
end

#define_writer_method(property, method_name, visibility) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



108
109
110
111
112
113
114
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 108

def define_writer_method(property, method_name, visibility)
  property_set = self
  parent.send(:define_method, method_name) do |value|
    property_set[property.name]= value
  end
  parent.send(visibility, method_name)
end

#each {|property| ... } ⇒ self

Iterate over properties

Yields:

Yield Parameters:

Returns:

  • (self)


37
38
39
40
41
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 37

def each
  return to_enum unless block_given?
  @map.each { |name, property| yield property if name.is_a?(Symbol) }
  self
end

#empty?Boolean

Check if properties exist

Returns:

  • (Boolean)


96
97
98
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 96

def empty?
  @map.empty?
end

#to_hashObject

Convert properties to a hash of property names and corresponding values



86
87
88
89
90
91
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 86

def to_hash
  properties.each_with_object({}) do |property, props|
    name = property.name
    props[name] = self[name]
  end
end

#update_map(name, property) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update map with index



78
79
80
# File 'lib/bitbucket_rest_api/api/config/property_set.rb', line 78

def update_map(name, property)
  @map[name.to_sym] = @map[name.to_s.freeze] = property
end