Class: CocoapodsSourceFix::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-source-fix/configuration.rb

Overview

读取独立配置文件(默认 <Podfile 目录>/cocoapods-source-fix.yml)

Constant Summary collapse

CONFIG_FILE_NAME =
'cocoapods-source-fix.yml'
ENV_KEY =
'COCOAPODS_SOURCE_FIX_CONFIG'
ENV_VERBOSE_KEY =
'COCOAPODS_SOURCE_FIX_VERBOSE'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, podfile_dir:) ⇒ Configuration

Returns a new instance of Configuration.



22
23
24
25
26
27
# File 'lib/cocoapods-source-fix/configuration.rb', line 22

def initialize(path, podfile_dir:)
  @path = path
  @data = YAML.load_file(path) || {}
  @rules = Array(@data['rules']).map { |raw| Rule.new(raw, base_dir: podfile_dir) }
  @verbose = parse_verbose
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/cocoapods-source-fix/configuration.rb', line 11

def path
  @path
end

#rulesObject (readonly)

Returns the value of attribute rules.



11
12
13
# File 'lib/cocoapods-source-fix/configuration.rb', line 11

def rules
  @rules
end

#verboseObject (readonly)

Returns the value of attribute verbose.



11
12
13
# File 'lib/cocoapods-source-fix/configuration.rb', line 11

def verbose
  @verbose
end

Class Method Details

.locate(podfile_dir) ⇒ Object

定位配置文件:环境变量优先,其次 Podfile 同目录默认文件名



14
15
16
17
18
19
20
# File 'lib/cocoapods-source-fix/configuration.rb', line 14

def self.locate(podfile_dir)
  env_path = ENV[ENV_KEY]
  return Pathname.new(env_path) if env_path && File.file?(env_path)

  default = File.join(podfile_dir, CONFIG_FILE_NAME)
  File.file?(default) ? Pathname.new(default) : nil
end