Class: Assembla::API::Config::PropertySet
- Inherits:
-
Object
- Object
- Assembla::API::Config::PropertySet
- Includes:
- Enumerable
- Defined in:
- lib/assembla_api/api/config/property_set.rb
Overview
Class responsible for storing configuration properties
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
-
#<<(property) ⇒ self
Adds property to the set.
-
#[](name) ⇒ Object
(also: #fetch)
Access property by name.
-
#[]=(name, property) ⇒ Object
Set property value by name.
- #define_reader_method(property, method_name, visibility) ⇒ Object private
- #define_writer_method(property, method_name, visibility) ⇒ Object private
-
#each {|property| ... } ⇒ self
Iterate over properties.
-
#empty? ⇒ Boolean
Check if properties exist.
-
#initialize(parent = nil, properties = Set.new) ⇒ undefined
constructor
private
Initialize an PropertySet.
-
#to_hash ⇒ Object
Convert properties to a hash of property names and corresponding values.
-
#update_map(name, property) ⇒ Object
private
Update map with index.
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
23 24 25 26 27 |
# File 'lib/assembla_api/api/config/property_set.rb', line 23 def initialize(parent = nil, properties = Set.new) @parent = parent @properties = properties @map = {} end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
11 12 13 |
# File 'lib/assembla_api/api/config/property_set.rb', line 11 def parent @parent end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
13 14 15 |
# File 'lib/assembla_api/api/config/property_set.rb', line 13 def properties @properties end |
Instance Method Details
#<<(property) ⇒ self
Adds property to the set
54 55 56 57 58 59 |
# File 'lib/assembla_api/api/config/property_set.rb', line 54 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
64 65 66 |
# File 'lib/assembla_api/api/config/property_set.rb', line 64 def [](name) @map[name] end |
#[]=(name, property) ⇒ Object
Set property value by name
72 73 74 |
# File 'lib/assembla_api/api/config/property_set.rb', line 72 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.
102 103 104 105 106 |
# File 'lib/assembla_api/api/config/property_set.rb', line 102 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.
109 110 111 112 113 114 115 |
# File 'lib/assembla_api/api/config/property_set.rb', line 109 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
38 39 40 41 42 |
# File 'lib/assembla_api/api/config/property_set.rb', line 38 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
97 98 99 |
# File 'lib/assembla_api/api/config/property_set.rb', line 97 def empty? @map.empty? end |
#to_hash ⇒ Object
Convert properties to a hash of property names and corresponding values
87 88 89 90 91 92 |
# File 'lib/assembla_api/api/config/property_set.rb', line 87 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
79 80 81 |
# File 'lib/assembla_api/api/config/property_set.rb', line 79 def update_map(name, property) @map[name.to_sym] = @map[name.to_s.freeze] = property end |