Class: TaaS::Contracts

Inherits:
Object
  • Object
show all
Defined in:
lib/helper/contracts.rb

Constant Summary collapse

@@contract_hash =
{}

Class Method Summary collapse

Class Method Details

.contains?(contract_name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/helper/contracts.rb', line 16

def self.contains?(contract_name)
  @@contract_hash.keys.include?(contract_name)
end

.get_all_contractsObject



31
32
33
# File 'lib/helper/contracts.rb', line 31

def self.get_all_contracts
  return @@contract_hash
end

.get_contract(contract_name) ⇒ Object



20
21
22
23
24
# File 'lib/helper/contracts.rb', line 20

def self.get_contract(contract_name)
  return nil unless contains?(contract_name)
  contract = Contract.new @@contract_hash[contract_name]
  contract
end

.get_execution_attribute(attribute, contract_name) ⇒ Object



26
27
28
29
# File 'lib/helper/contracts.rb', line 26

def self.get_execution_attribute(attribute, contract_name)
  return nil if @@contract_hash.nil? || @@contract_hash.eql?({})
  @@contract_hash["contracts"][contract_name.to_s][attribute]
end

.is_empty?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/helper/contracts.rb', line 12

def self.is_empty?
  @@contract_hash.eql?({}) || @@contract_hash.nil?
end

.load(absolute_path) ⇒ Object



6
7
8
9
10
# File 'lib/helper/contracts.rb', line 6

def self.load(absolute_path)
  raise "File path cant be nil or empty" if (absolute_path.nil? || absolute_path.empty?)
  puts "Loading contracts file from #{absolute_path}"
  @@contract_hash = YAML.load_file(absolute_path)["contracts"] rescue {}
end