Class: Konfig::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/konfig/schema.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchema

Returns a new instance of Schema.



13
14
15
# File 'lib/konfig/schema.rb', line 13

def initialize
  @groups = {}
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



11
12
13
# File 'lib/konfig/schema.rb', line 11

def groups
  @groups
end

Class Method Details

.draw(&block) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/konfig/schema.rb', line 40

def draw(&block)
  schema = new
  if block
    dsl = SchemaDSL.new(schema)
    dsl.instance_eval(&block)
  end
  schema
end

Instance Method Details

#add_group(name) {|group| ... } ⇒ Object

Yields:



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/konfig/schema.rb', line 21

def group?(name)
  @groups.key?(name)
end