class Github::API::Config::PropertySet

Class responsible for storing configuration properties

Attributes

parent[R]
properties[R]

Public Class Methods

new(parent = nil, properties = Set.new) click to toggle source

Initialize an PropertySet

@param [Object] parent @param [Set] properties

@return [undefined]

@api private

# File lib/github_api/api/config/property_set.rb, line 24
def initialize(parent = nil, properties = Set.new)
  @parent = parent
  @properties = properties
  @map = {}
end

Public Instance Methods

<<(property) click to toggle source

Adds property to the set

@example

properties_set << property

@param [Property] property

@return [self]

@api public

# File lib/github_api/api/config/property_set.rb, line 55
def <<(property)
  properties << property
  update_map(property.name, property.default)
  property.define_accessor_methods(self)
  self
end
[](name) click to toggle source

Access property by name

@api public

# File lib/github_api/api/config/property_set.rb, line 65
def [](name)
  @map[name]
end
Also aliased as: fetch
[]=(name, property) click to toggle source

Set property value by name

@api public

# File lib/github_api/api/config/property_set.rb, line 73
def []=(name, property)
  update_map(name, property)
end
define_reader_method(property, method_name, visibility) click to toggle source

@api private

# File lib/github_api/api/config/property_set.rb, line 103
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) click to toggle source

@api private

# File lib/github_api/api/config/property_set.rb, line 110
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| ... } click to toggle source

Iterate over properties

@yield [property]

@yieldparam [Property] property

@return [self]

@api public

# File lib/github_api/api/config/property_set.rb, line 39
def each
  return to_enum unless block_given?
  @map.each { |name, property| yield property if name.is_a?(Symbol) }
  self
end
empty?() click to toggle source

Check if properties exist

@api public

# File lib/github_api/api/config/property_set.rb, line 98
def empty?
  @map.empty?
end
fetch(name)
Alias for: []
to_hash() click to toggle source

Convert properties to a hash of property names and corresponding values

@api public

# File lib/github_api/api/config/property_set.rb, line 88
def to_hash
  properties.each_with_object({}) do |property, props|
    name = property.name
    props[name] = self[name]
  end
end
update_map(name, property) click to toggle source

Update map with index

@api private

# File lib/github_api/api/config/property_set.rb, line 80
def update_map(name, property)
  @map[name.to_sym] = @map[name.to_s.freeze] = property
end