Class: KCommercial::Resources::KeyDefines

Inherits:
Object
  • Object
show all
Defined in:
lib/KCommercialPipeline/core/resource/key_defines.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ KeyDefines

Returns a new instance of KeyDefines.



32
33
34
35
36
37
# File 'lib/KCommercialPipeline/core/resource/key_defines.rb', line 32

def initialize(hash = {})
  @keys = hash['keys'] or hash[:keys]
  if @keys.nil?
    @keys = []
  end
end

Instance Attribute Details

#defined_in_fileObject

The configuration file defines in the storage path



30
31
32
# File 'lib/KCommercialPipeline/core/resource/key_defines.rb', line 30

def defined_in_file
  @defined_in_file
end

#keysObject (readonly)

All the key defines for the generator



27
28
29
# File 'lib/KCommercialPipeline/core/resource/key_defines.rb', line 27

def keys
  @keys
end

Class Method Details

.from_file(file) ⇒ KeyDefines

Creat a new KeyDefines from a file

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/KCommercialPipeline/core/resource/key_defines.rb', line 11

def from_file(file)
  unless file
    KCommercial::UI.debug "can not find the key defines file #{file}"
    return  nil
  end
  contents = File.read(file)
  hash = YAML.load contents
  unless hash.is_a? Hash
    raise KCommercial::Exception("The content is not an hash in #{file}")
  end
  keys = KeyDefines.new(hash)
  keys.defined_in_file = file
  keys
end