Class: Kondate::RoleFile

Inherits:
Object
  • Object
show all
Defined in:
lib/kondate/role_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, role, ext = nil) ⇒ RoleFile

Returns a new instance of RoleFile.



11
12
13
14
15
# File 'lib/kondate/role_file.rb', line 11

def initialize(dir, role, ext = nil)
  @dir = dir
  @role = role
  @ext = ext
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



5
6
7
# File 'lib/kondate/role_file.rb', line 5

def dir
  @dir
end

#extObject (readonly)

Returns the value of attribute ext.



5
6
7
# File 'lib/kondate/role_file.rb', line 5

def ext
  @ext
end

#roleObject (readonly)

Returns the value of attribute role.



5
6
7
# File 'lib/kondate/role_file.rb', line 5

def role
  @role
end

Class Method Details

.explore(dir, role, ext = nil) ⇒ Object



7
8
9
# File 'lib/kondate/role_file.rb', line 7

def self.explore(dir, role, ext = nil)
  self.new(dir, role, ext).explore
end

Instance Method Details

#exploreString

Returns readable role file exploring possible role files. For example, if ‘role` is `myapp-web-staging`, this method explores files as

  1. myapp-web-staging.yml

  2. myapp-web-base.yml

  3. myapp-web.yml

  4. myapp-base.yml

  5. myapp.yml

  6. base.yml

Returns:

  • (String)

    detected file path or last candidate path



28
29
30
31
32
33
34
35
# File 'lib/kondate/role_file.rb', line 28

def explore
  paths = if Config.explore_role_files?
            possible_paths
          else
            [get_path]
          end
  paths.find {|path| File.readable?(path) } || paths.last
end