Class: Pod::Extension::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-extension/configure.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_url, project_debug_url) ⇒ Configurator

Returns a new instance of Configurator.



34
35
36
# File 'lib/cocoapods-extension/configure.rb', line 34

def initialize project_url, project_debug_url
    @conf = { 'project_url' => project_url.to_s, 'project_debug_url' => project_debug_url.to_s }
end

Instance Attribute Details

#confObject (readonly)

Returns the value of attribute conf.



32
33
34
# File 'lib/cocoapods-extension/configure.rb', line 32

def conf
  @conf
end

Class Method Details

.create_conf!(project_url) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/cocoapods-extension/configure.rb', line 21

def self.create_conf! project_url
    index = 0
    name = File.basename(project_url)
    projects = Pod::Extension::Sandbox::workspace::projects
    begin 
        project_debug_url = projects::root + "#{name}@#{index}"
        index += 1
    end while project_debug_url.exist?
    Pod::Extension::Configurator::new project_url, project_debug_url
end

.find_conf?(project_url) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cocoapods-extension/configure.rb', line 7

def self.find_conf? project_url
    projects = Pod::Extension::Sandbox::workspace::projects
    for project_debug_url in Dir.glob(projects::root + '*') do
        conf = Pod::Extension::Configurator::new project_url, project_debug_url
        if conf.verify?
            break
        end
    end
    if conf.nil? || !conf.verify?
        conf = nil
    end
    conf
end

Instance Method Details

#project_debug_urlObject



46
47
48
# File 'lib/cocoapods-extension/configure.rb', line 46

def project_debug_url
    @conf['project_debug_url']
end

#project_urlObject



42
43
44
# File 'lib/cocoapods-extension/configure.rb', line 42

def project_url
    @conf['project_url']
end

#save!Object



72
73
74
75
# File 'lib/cocoapods-extension/configure.rb', line 72

def save!
    return nil if verify?
    File.write(url, @conf.to_json)
end

#syncObject



63
64
65
66
67
68
69
70
# File 'lib/cocoapods-extension/configure.rb', line 63

def sync
    begin json = JSON.parse(File.read(url))
    rescue => exception
    end
    unless json.nil?
        @conf = json.merge(@conf)
    end
end

#urlObject



38
39
40
# File 'lib/cocoapods-extension/configure.rb', line 38

def url
    File.join(project_debug_url, '.conf')
end

#verify?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cocoapods-extension/configure.rb', line 50

def verify?
    valid = false
    unless url.nil? || project_url.nil? || project_debug_url.nil?
        if File.exist?(url) && File.exist?(project_url) && File.exist?(project_debug_url)
            begin json = JSON.parse(File.read(url))
            rescue => exception 
            end
            valid = @conf == json
        end
    end
    valid
end