Class: Konfig::Schema
- Inherits:
-
Object
- Object
- Konfig::Schema
- Defined in:
- lib/konfig/schema.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
Class Method Summary collapse
Instance Method Summary collapse
- #add_group(name) {|group| ... } ⇒ Object
- #create_hash(source) ⇒ Object
- #group(name) ⇒ Object
- #group?(name) ⇒ Boolean
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
13 14 15 |
# File 'lib/konfig/schema.rb', line 13 def initialize @groups = {} end |
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
11 12 13 |
# File 'lib/konfig/schema.rb', line 11 def groups @groups end |
Class Method Details
Instance Method Details
#add_group(name) {|group| ... } ⇒ Object
25 26 27 28 29 30 |
# File 'lib/konfig/schema.rb', line 25 def add_group(name) group = SchemaGroup.new @groups[name] = group yield group if block_given? group end |
#create_hash(source) ⇒ Object
32 33 34 35 36 |
# File 'lib/konfig/schema.rb', line 32 def create_hash(source) @groups.each_with_object({}) do |(name, group), hash| hash[name] = group.create_hash([name], source) end end |
#group(name) ⇒ Object
17 18 19 |
# File 'lib/konfig/schema.rb', line 17 def group(name) @groups[name] || raise(GroupNotFoundError, "Group '#{name}' not found in schema") end |
#group?(name) ⇒ Boolean
21 22 23 |
# File 'lib/konfig/schema.rb', line 21 def group?(name) @groups.key?(name) end |