class Github::API::Config
A base class for constructing api configuration
Attributes
property_set[R]
Public Class Methods
inherited(descendant)
click to toggle source
Calls superclass method
# File lib/github_api/api/config.rb, line 58 def self.inherited(descendant) super (@subclasses ||= Set.new) << descendant descendant.instance_variable_set('@property_set', PropertySet.new(descendant, self.property_set.properties.dup)) end
new(&block)
click to toggle source
Calls superclass method
# File lib/github_api/api/config.rb, line 65 def initialize(&block) super(&block) end
property(name, options = {})
click to toggle source
Defines a property on an object's class or instance
@example
class Configuration < Api::Config property :adapter, default: :net_http property :user, required: true end
@param [Symbol] name
the name of a property
@param [#to_hash] options
the extra options
@return [self]
@api public
# File lib/github_api/api/config.rb, line 28 def self.property(name, options = {}) self.property_set << Property.new(name, options) update_subclasses(name, options) self end
property?(name)
click to toggle source
Check if property is defined
@param [Symbol] name
the name to check
@return [Boolean]
@api public
# File lib/github_api/api/config.rb, line 48 def self.property?(name) property_set.include?(name) end
property_names()
click to toggle source
# File lib/github_api/api/config.rb, line 73 def self.property_names property_set.properties.map(&:name) end
update_subclasses(name, options)
click to toggle source
# File lib/github_api/api/config.rb, line 34 def self.update_subclasses(name, options) if defined?(@subclasses) && @subclasses @subclasses.each { |klass| klass.property(name, options) } end end
Public Instance Methods
call(&block)
click to toggle source
Provide access to properties
@example
config.call do |config| config.adapter = :net_http end
@return [self]
@api private
# File lib/github_api/api/config.rb, line 100 def call(&block) block.call(self) if block_given? self end
fetch(value = nil)
click to toggle source
Fetach all the properties and their values
@return [Hash]
@api public
# File lib/github_api/api/config.rb, line 82 def fetch(value = nil) if value self.class.property_set[value] else self.class.property_set.to_hash end end
property_names()
click to toggle source
# File lib/github_api/api/config.rb, line 69 def property_names self.class.property_set.properties.map(&:name) end