Class: BitBucket::API::Config
- Inherits:
-
Object
- Object
- BitBucket::API::Config
- Defined in:
- lib/bitbucket_rest_api/api/config.rb,
lib/bitbucket_rest_api/api/config/property.rb,
lib/bitbucket_rest_api/api/config/property_set.rb
Overview
A base class for constructing api configuration
Direct Known Subclasses
Defined Under Namespace
Classes: Property, PropertySet
Class Attribute Summary collapse
-
.property_set ⇒ Object
readonly
Returns the value of attribute property_set.
Class Method Summary collapse
- .inherited(descendant) ⇒ Object
-
.property(name, options = {}) ⇒ self
Defines a property on an object’s class or instance.
-
.property?(name) ⇒ Boolean
Check if property is defined.
- .property_names ⇒ Object
- .update_subclasses(name, options) ⇒ Object
Instance Method Summary collapse
-
#call(&block) ⇒ self
private
Provide access to properties.
-
#fetch(value = nil) ⇒ Hash[Symbol]
Fetach all the properties and their values.
-
#initialize(&block) ⇒ Config
constructor
A new instance of Config.
- #property_names ⇒ Object
Constructor Details
#initialize(&block) ⇒ Config
Returns a new instance of Config.
66 67 68 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 66 def initialize(&block) super(&block) end |
Class Attribute Details
.property_set ⇒ Object (readonly)
Returns the value of attribute property_set.
54 55 56 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 54 def property_set @property_set end |
Class Method Details
.inherited(descendant) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 59 def self.inherited(descendant) super (@subclasses ||= Set.new) << descendant descendant.instance_variable_set('@property_set', PropertySet.new(descendant, self.property_set.properties.dup)) end |
.property(name, options = {}) ⇒ self
Defines a property on an object’s class or instance
29 30 31 32 33 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 29 def self.property(name, = {}) self.property_set << Property.new(name, ) update_subclasses(name, ) self end |
.property?(name) ⇒ Boolean
Check if property is defined
49 50 51 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 49 def self.property?(name) property_set.include?(name) end |
.property_names ⇒ Object
74 75 76 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 74 def self.property_names property_set.properties.map(&:name) end |
.update_subclasses(name, options) ⇒ Object
35 36 37 38 39 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 35 def self.update_subclasses(name, ) if defined?(@subclasses) && @subclasses @subclasses.each { |klass| klass.property(name, ) } end end |
Instance Method Details
#call(&block) ⇒ self
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.
Provide access to properties
101 102 103 104 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 101 def call(&block) block.call(self) if block_given? self end |
#fetch(value = nil) ⇒ Hash[Symbol]
Fetach all the properties and their values
83 84 85 86 87 88 89 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 83 def fetch(value = nil) if value self.class.property_set[value] else self.class.property_set.to_hash end end |
#property_names ⇒ Object
70 71 72 |
# File 'lib/bitbucket_rest_api/api/config.rb', line 70 def property_names self.class.property_set.properties.map(&:name) end |