gapic-common - Module Gapic::Config (v1.1.0)
Stay organized with collections
Save and categorize content based on your preferences.
Reference documentation and code samples for the gapic-common module Gapic::Config.
Config is a simple DSL for creating Configuration classes.
Example
require
"gapic/config"
class
SampleConfig
extend
Gapic
::
Config
config_attr
:name
,
nil
,
String
,
nil
config_attr
:active
,
true
,
true
,
false
config_attr
:count
,
nil
,
Numeric
,
nil
config_attr
:env
,
:production
,
String
,
Symbol
def
initialize
parent_config
=
nil
@parent_config
=
parent_config
unless
parent_config
.
nil?
yield
self
if
block_given?
end
end
config
=
SampleConfig
.
new
config
.
name
#=> nil
config
.
name
=
"thor"
#=> "thor"
config
.
name
#=> "thor"
config
.
name
=
:thor
# ArgumentError
Methods
#config_attr
def
config_attr
(
name
,
default
,
*
valid_values
,
& validator
)
Add configuration attribute methods to the configuratin class.
Parameters - name(String, Symbol) — The name of the option
- default(Object, nil) — Initial value (nil is allowed)
- valid_values(Array) — A list of valid types
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-04 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# gapic-common - Module Gapic::Config (v1.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.1.0 (latest)](/ruby/docs/reference/gapic-common/latest/Gapic-Config)\n- [1.0.1](/ruby/docs/reference/gapic-common/1.0.1/Gapic-Config)\n- [0.26.0](/ruby/docs/reference/gapic-common/0.26.0/Gapic-Config)\n- [0.25.0](/ruby/docs/reference/gapic-common/0.25.0/Gapic-Config)\n- [0.24.0](/ruby/docs/reference/gapic-common/0.24.0/Gapic-Config) \nReference documentation and code samples for the gapic-common module Gapic::Config.\n\nConfig is a simple DSL for creating Configuration classes.\n\nExample\n-------\n\n```ruby\nrequire \"gapic/config\"\n\nclass SampleConfig\n extend Gapic::Config\n\n config_attr :name, nil, String, nil\n config_attr :active, true, true, false\n config_attr :count, nil, Numeric, nil\n config_attr :env, :production, String, Symbol\n\n def initialize parent_config = nil\n @parent_config = parent_config unless parent_config.nil?\n yield self if block_given?\n end\nend\n\nconfig = SampleConfig.new\n\nconfig.name #=\u003e nil\nconfig.name = \"thor\" #=\u003e \"thor\"\nconfig.name #=\u003e \"thor\"\nconfig.name = :thor # ArgumentError\n```\n\nMethods\n-------\n\n### #config_attr\n\n def config_attr(name, default, *valid_values, &validator)\n\nAdd configuration attribute methods to the configuratin class. \n**Parameters**\n\n- **name** (String, Symbol) --- The name of the option\n- **default** (Object, nil) --- Initial value (nil is allowed)\n- **valid_values** (Array) --- A list of valid types \n**Raises**\n\n- (NameError)"]]