Class: JobSpec::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/job_spec/role.rb

Defined Under Namespace

Classes: Expectations

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Role

Returns a new instance of Role.



23
24
25
26
27
# File 'lib/job_spec/role.rb', line 23

def initialize(name, &block)
  @name = name
  @expectations = []
  instance_eval(&block) if block_given?
end

Class Method Details

.add_expectations(role_expectations) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/job_spec/role.rb', line 12

def self.add_expectations(role_expectations)
  role_expectations.each do |role_expectation|
    role = @definitions[role_expectation[:name]]
    role_expectation[:expectations].each do |e|
      role.expected(e[:expectation], e[:description])
    end
  end

  nil
end

.definition(name, &block) ⇒ Object



3
4
5
6
# File 'lib/job_spec/role.rb', line 3

def self.definition(name, &block)
  @definitions ||= {}
  @definitions[name] = new(name, &block)
end

.definitionsObject



8
9
10
# File 'lib/job_spec/role.rb', line 8

def self.definitions
  @definitions.values
end

Instance Method Details

#description(description = nil) ⇒ Object



33
34
35
# File 'lib/job_spec/role.rb', line 33

def description(description = nil)
  @description = @description || description
end

#expectationsObject



49
50
51
# File 'lib/job_spec/role.rb', line 49

def expectations
  @expectations
end

#expected(expectation, description = nil) ⇒ Object



45
46
47
# File 'lib/job_spec/role.rb', line 45

def expected(expectation, description = nil)
  @expectations << { expectation: expectation, description: description, group: nil }
end

#include(role_expectations, as:) ⇒ Object



41
42
43
# File 'lib/job_spec/role.rb', line 41

def include(role_expectations, as:)
  @expectations.concat(role_expectations.to_a.map { |expectation| expectation.merge(group: as) })
end

#nameObject



29
30
31
# File 'lib/job_spec/role.rb', line 29

def name
  @name
end

#salary(range = nil) ⇒ Object



37
38
39
# File 'lib/job_spec/role.rb', line 37

def salary(range = nil)
  @salary = @salary || range
end