Class: RspecApiDocumentation::Configuration
- Inherits:
-
Object
- Object
- RspecApiDocumentation::Configuration
- Includes:
- Enumerable
- Defined in:
- lib/rspec_api_documentation/configuration.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #client_method ⇒ Object
- #client_method=(new_client_method) ⇒ Object
-
#define_group(name) {|subconfig| ... } ⇒ Object
Defines a new sub configuration.
- #disable_dsl_method! ⇒ Object
- #disable_dsl_status! ⇒ Object
-
#each {|_self| ... } ⇒ Object
Yields itself and sub groups to hook into the Enumerable module.
- #groups ⇒ Object
-
#initialize(parent = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #settings ⇒ Object
Constructor Details
#initialize(parent = nil) ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 |
# File 'lib/rspec_api_documentation/configuration.rb', line 7 def initialize(parent = nil) @parent = parent @settings = parent.settings.clone if parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/rspec_api_documentation/configuration.rb', line 5 def parent @parent end |
Class Method Details
.add_setting(name, opts = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rspec_api_documentation/configuration.rb', line 41 def self.add_setting(name, opts = {}) define_method("#{name}=") { |value| settings[name] = value } define_method("#{name}") do if settings.has_key?(name) settings[name] elsif opts[:default].respond_to?(:call) opts[:default].call(self) else opts[:default] end end end |
Instance Method Details
#client_method ⇒ Object
129 130 131 |
# File 'lib/rspec_api_documentation/configuration.rb', line 129 def client_method @client_method ||= :client end |
#client_method=(new_client_method) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/rspec_api_documentation/configuration.rb', line 120 def client_method=(new_client_method) RspecApiDocumentation::DSL::Resource.module_eval <<-RUBY alias :#{new_client_method} #{client_method} undef #{client_method} RUBY @client_method = new_client_method end |
#define_group(name) {|subconfig| ... } ⇒ Object
Defines a new sub configuration
Automatically sets the ‘filter` to the group name, and the `docs_dir` to a subfolder of the parent’s ‘doc_dir` named the group name.
RspecApiDocumentation.configure do |config|
config.docs_dir = "doc/api"
config.define_group(:public) do |config|
# Default values
config.docs_dir = "doc/api/public"
config.filter = :public
end
end
Params:
name
-
String name of the group
block
-
Block configuration block
33 34 35 36 37 38 39 |
# File 'lib/rspec_api_documentation/configuration.rb', line 33 def define_group(name, &block) subconfig = self.class.new(self) subconfig.filter = name subconfig.docs_dir = self.docs_dir.join(name.to_s) yield subconfig groups << subconfig end |
#disable_dsl_method! ⇒ Object
139 140 141 142 143 |
# File 'lib/rspec_api_documentation/configuration.rb', line 139 def disable_dsl_method! RspecApiDocumentation::DSL::Endpoint.module_eval <<-RUBY undef method RUBY end |
#disable_dsl_status! ⇒ Object
133 134 135 136 137 |
# File 'lib/rspec_api_documentation/configuration.rb', line 133 def disable_dsl_status! RspecApiDocumentation::DSL::Endpoint.module_eval <<-RUBY undef status RUBY end |
#each {|_self| ... } ⇒ Object
Yields itself and sub groups to hook into the Enumerable module
150 151 152 153 |
# File 'lib/rspec_api_documentation/configuration.rb', line 150 def each(&block) yield self groups.map { |g| g.each &block } end |
#groups ⇒ Object
12 13 14 |
# File 'lib/rspec_api_documentation/configuration.rb', line 12 def groups @groups ||= [] end |
#settings ⇒ Object
145 146 147 |
# File 'lib/rspec_api_documentation/configuration.rb', line 145 def settings @settings ||= {} end |