Class: Github::API::Config
- Inherits:
-
Object
- Object
- Github::API::Config
- Defined in:
- lib/github_api2/api/config.rb,
lib/github_api2/api/config/property.rb,
lib/github_api2/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]
Fetch 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.
64 65 66 |
# File 'lib/github_api2/api/config.rb', line 64 def initialize(&block) super(&block) end |
Class Attribute Details
.property_set ⇒ Object (readonly)
Returns the value of attribute property_set.
52 53 54 |
# File 'lib/github_api2/api/config.rb', line 52 def property_set @property_set end |
Class Method Details
.inherited(descendant) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/github_api2/api/config.rb', line 57 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
27 28 29 30 31 |
# File 'lib/github_api2/api/config.rb', line 27 def self.property(name, = {}) self.property_set << Property.new(name, ) update_subclasses(name, ) self end |
.property?(name) ⇒ Boolean
Check if property is defined
47 48 49 |
# File 'lib/github_api2/api/config.rb', line 47 def self.property?(name) property_set.include?(name) end |
.property_names ⇒ Object
72 73 74 |
# File 'lib/github_api2/api/config.rb', line 72 def self.property_names property_set.properties.map(&:name) end |
.update_subclasses(name, options) ⇒ Object
33 34 35 36 37 |
# File 'lib/github_api2/api/config.rb', line 33 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
99 100 101 102 |
# File 'lib/github_api2/api/config.rb', line 99 def call(&block) block.call(self) if block_given? self end |
#fetch(value = nil) ⇒ Hash[Symbol]
Fetch all the properties and their values
81 82 83 84 85 86 87 |
# File 'lib/github_api2/api/config.rb', line 81 def fetch(value = nil) if value self.class.property_set[value] else self.class.property_set.to_hash end end |
#property_names ⇒ Object
68 69 70 |
# File 'lib/github_api2/api/config.rb', line 68 def property_names self.class.property_set.properties.map(&:name) end |