Class: BitBucket::API::Config

Inherits:
Object
  • Object
show all
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

Configuration

Defined Under Namespace

Classes: Property, PropertySet

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_setObject (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

Examples:

class Configuration < Api::Config
  property :adapter, default: :net_http
  property :user, required: true
end

Parameters:

  • name (Symbol)

    the name of a property

  • options (#to_hash) (defaults to: {})

    the extra options

Returns:

  • (self)


29
30
31
32
33
# File 'lib/bitbucket_rest_api/api/config.rb', line 29

def self.property(name, options = {})
  self.property_set << Property.new(name, options)
  update_subclasses(name, options)
  self
end

.property?(name) ⇒ Boolean

Check if property is defined

Parameters:

  • name (Symbol)

    the name to check

Returns:

  • (Boolean)


49
50
51
# File 'lib/bitbucket_rest_api/api/config.rb', line 49

def self.property?(name)
  property_set.include?(name)
end

.property_namesObject



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, options)
  if defined?(@subclasses) && @subclasses
    @subclasses.each { |klass| klass.property(name, options) }
  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

Examples:

config.call do |config|
  config.adapter = :net_http
end

Returns:

  • (self)


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

Returns:



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_namesObject



70
71
72
# File 'lib/bitbucket_rest_api/api/config.rb', line 70

def property_names
  self.class.property_set.properties.map(&:name)
end