Class: European::CarryAll

Inherits:
Object
  • Object
show all
Defined in:
lib/european/carry_all.rb,
lib/european/carry_all.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCarryAll

Returns a new instance of CarryAll.



5
6
7
8
9
10
11
# File 'lib/european/carry_all.rb', line 5

def initialize
  @projects = {}
  @build_systems = {}
  @deploy_systems = {}
  @source_systems = {}
  @post_setup_procs = []
end

Class Method Details

.load_file(file) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/european/carry_all.rb', line 153

def self.load_file(file)
  carry_all = CarryAll.new
  lambda {
    # TODO: Is there any way to define this.. just on an object..
    # and have that DSL file be loaded in the context of that object?
    Kernel.send :define_method, :project do |name, &block|
      carry_all.add_project(European::Project.new({name: name, proc: block, carry_all: carry_all}))
    end

    Kernel.send :define_method, :build do |name|
      carry_all.after_setup do
        ni = NameInterpreter.new name
        build_system_name = ni.prefix
        build_name = ni.name
        build_system = @build_systems[build_system_name]
        if build_system.build named: name
          raise "#{build_system} already has a build named #{name}'"
        end
        url = build_system.url_for_project_named build_name
        build = Build.new build_system: build_system, project: nil, name: build_name, url: url
        build_system.add_build build
      end
    end

    Kernel.send :define_method, :build_system do |name, &block|
      carry_all.add_build_system(European::BuildSystem.new({name: name, proc: block, carry_all: carry_all}))
    end

    Kernel.send :define_method, :deploy_system do |name, &block|
      carry_all.add_deploy_system(European::DeploySystem.new({name: name, proc: block, carry_all: carry_all}))
    end

    Kernel.send :define_method, :source_system do |name, &block|
      carry_all.add_source_system(European::SourceSystem.new({name: name, proc: block, carry_all: carry_all}))
    end
  }.call
  load file
  carry_all.setup
  carry_all
end

.load_url(url) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/european/carry_all.rb', line 145

def self.load_url(url)
  file = Tempfile.new 'carry_all'
  url_content = open(url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE).read
  file.write url_content
  file.close
  load_file file.path
end

Instance Method Details

#add_build_system(build_system) ⇒ Object



34
35
36
# File 'lib/european/carry_all.rb', line 34

def add_build_system(build_system)
  @build_systems[build_system.name] = build_system
end

#add_deploy_system(deploy_system) ⇒ Object



38
39
40
# File 'lib/european/carry_all.rb', line 38

def add_deploy_system(deploy_system)
  @deploy_systems[deploy_system.name] = deploy_system
end

#add_project(project) ⇒ Object



30
31
32
# File 'lib/european/carry_all.rb', line 30

def add_project(project)
  @projects[project.name] = project
end

#add_source_system(source_system) ⇒ Object



42
43
44
# File 'lib/european/carry_all.rb', line 42

def add_source_system(source_system)
  @source_systems[source_system.name] = source_system
end

#after_setup(&block) ⇒ Object



46
47
48
# File 'lib/european/carry_all.rb', line 46

def after_setup(&block)
  @post_setup_procs << block
end

#build_system(args) ⇒ Object



62
63
64
65
# File 'lib/european/carry_all.rb', line 62

def build_system(args)
  named = args[:named] || raise(':named is required')
  @build_systems[named]
end

#build_systemsObject



67
68
69
# File 'lib/european/carry_all.rb', line 67

def build_systems
  @build_systems.values
end

#deploy_system(args) ⇒ Object



71
72
73
74
# File 'lib/european/carry_all.rb', line 71

def deploy_system(args)
  named = args[:named] || raise(':named is required')
  @deploy_systems[named]
end

#deploy_systemsObject



76
77
78
# File 'lib/european/carry_all.rb', line 76

def deploy_systems
  @deploy_systems.values
end

#project(args) ⇒ Object

TODO: Ack! This is shadowing the kernel defined ‘project’ from the DSL portion in load_file. Is there anyway to avoid globally defining ‘project’?



53
54
55
56
# File 'lib/european/carry_all.rb', line 53

def project(args)
  named = args[:named] || raise(':named is required')
  @projects[named]
end

#projectsObject



58
59
60
# File 'lib/european/carry_all.rb', line 58

def projects
  @projects.values
end

#register(item, action, name) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/european/carry_all.rb', line 89

def register(item, action, name)
  if item.class == Project
    project = item
    if action == :has_build
      ni = NameInterpreter.new name
      build_system_name = ni.prefix
      build_name = ni.name
      build_system = build_systems.find { |bs| bs.name == build_system_name }
      if build_system.build named: build_name
        raise "#{build_system} already has a build named #{build_name}'"
      end
      url = build_system.url_for_project_named build_name
      build = Build.new build_system: build_system, project: project, name: build_name, url: url
      build_system.add_build build
      build_system.add_project project
      project.add_build_system build_system
      project.add_build build
    elsif action == :is_hosted_on
      source_system = @source_systems[name]
      raise "Unknown SourceSystem '#{name}'" unless source_system
      project.source_system = source_system
      source_system.add_project project
      url = source_system.src_url_for_project_named project.name
      project.src_url = url
    elsif action == :deploys_from
      deploy_system = @deploy_systems[name]
      raise "Unknown DeploySystem '#{name}'" unless deploy_system
      project.deploy_systems << deploy_system
      deploy_system.add_project project
    elsif action == :has_deploy
      ni = NameInterpreter.new name
      deploy_system_name = ni.prefix
      build_name = ni.name
      deploy_system = deploy_systems.find { |ds| ds.name == deploy_system_name }
      if deploy_system.build named: build_name
        raise "#{deploy_system} already has a deploy named '#{build_name}'"
      end
      url = deploy_system.url_for_project_named build_name
      deploy = Build.new build_system: deploy_system, project: project, name: build_name, url: url
      deploy_system.add_build deploy
      project.add_deploy deploy
    end
  end
end

#setupObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/european/carry_all.rb', line 13

def setup
  @source_systems.values.each { |system| system.setup }
  @build_systems.values.each { |system| system.setup }
  @deploy_systems.values.each { |system| system.setup }
  default_project = @projects['defaults']
  default_project.setup if default_project
  @projects.delete 'defaults'
  @projects.values.each do |project|
    next if project == default_project
    project.exec default_project.proc if default_project
    project.setup
  end
  @post_setup_procs.each do |proc|
    instance_eval &proc
  end
end

#source_system(args) ⇒ Object



80
81
82
83
# File 'lib/european/carry_all.rb', line 80

def source_system(args)
  named = args[:named] || raise(':named is required')
  @source_systems[named]
end

#source_systemsObject



85
86
87
# File 'lib/european/carry_all.rb', line 85

def source_systems
  @source_systems.values
end