Module: DSLCompose::DSLs

Defined in:
lib/dsl_compose/dsls.rb

Defined Under Namespace

Classes: ClassDSLDefinitionDoesNotExistError, DSLAlreadyExistsError, NoDSLDefinitionsForClassError

Class Method Summary collapse

Class Method Details

.class_dsl(klass, name) ⇒ Object

return a specific DSL definition for a provided class if it does not exist, then an error is raised



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dsl_compose/dsls.rb', line 53

def self.class_dsl klass, name
  if @dsls.key? klass
    if @dsls[klass].key? name
      @dsls[klass][name]
    else
      raise ClassDSLDefinitionDoesNotExistError, "The requested DSL `#{name}` does not exist on this class"
    end
  else
    raise NoDSLDefinitionsForClassError, "No DSLs have been defined for this class"
  end
end

.class_dsl_exists?(klass, name) ⇒ Boolean

if a DSL witg the provided name exists for the provided class, then return true else return false

Returns:

  • (Boolean)


37
38
39
# File 'lib/dsl_compose/dsls.rb', line 37

def self.class_dsl_exists? klass, name
  @dsls.key?(klass) && @dsls[klass].key?(name)
end

.class_dsls(klass) ⇒ Object

return an array of DSL definitions for a provided class, if no DSLs exist for the provided class, then an error is raised



43
44
45
46
47
48
49
# File 'lib/dsl_compose/dsls.rb', line 43

def self.class_dsls klass
  if @dsls.key? klass
    @dsls[klass].values
  else
    raise NoDSLDefinitionsForClassError, "No DSLs have been defined for this class"
  end
end

.create_dsl(klass, name) ⇒ Object

create a new DSL definition for a class ‘klass` here is the class in which `define_dsl` was called



20
21
22
23
24
25
26
27
28
# File 'lib/dsl_compose/dsls.rb', line 20

def self.create_dsl klass, name
  @dsls[klass] ||= {}

  if @dsls[klass].key? name
    raise DSLAlreadyExistsError, "A DSL with the name `#{name}` already exists"
  end

  @dsls[klass][name] = DSLCompose::DSL.new(name, klass)
end

.dslsObject

return all of the DSL definitions



31
32
33
# File 'lib/dsl_compose/dsls.rb', line 31

def self.dsls
  @dsls
end

.resetObject

removes all DSL deinitions, this method is typically used by the test suite for resetting state inbetween each test



67
68
69
# File 'lib/dsl_compose/dsls.rb', line 67

def self.reset
  @dsls = {}
end