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.



25
26
27
28
29
# File 'lib/job_spec/role.rb', line 25

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
22
23
# File 'lib/job_spec/role.rb', line 12

def self.add_expectations(role_expectations)
  expectation = role_expectations.first[:expectations].first

  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



35
36
37
# File 'lib/job_spec/role.rb', line 35

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

#expectationsObject



51
52
53
# File 'lib/job_spec/role.rb', line 51

def expectations
  @expectations
end

#expected(expectation, description = nil) ⇒ Object



47
48
49
# File 'lib/job_spec/role.rb', line 47

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

#include(role_expectations, as:) ⇒ Object



43
44
45
# File 'lib/job_spec/role.rb', line 43

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

#nameObject



31
32
33
# File 'lib/job_spec/role.rb', line 31

def name
  @name
end

#salary(range = nil) ⇒ Object



39
40
41
# File 'lib/job_spec/role.rb', line 39

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