Class: Prick::Environments

Inherits:
Object
  • Object
show all
Defined in:
lib/prick/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Environments

Returns a new instance of Environments.



130
131
132
133
134
135
136
# File 'lib/prick/environment.rb', line 130

def initialize(hash)
  @types = @@TYPES.dup
  @environments = {}
  parse_variables(hash)
  parse_environments(hash)
  analyze
end

Instance Attribute Details

#environmentsObject (readonly)

Map from environment name to Environment object



113
114
115
# File 'lib/prick/environment.rb', line 113

def environments
  @environments
end

#typesObject (readonly)

Maps from variable name (Symbol) to type (String)



119
120
121
# File 'lib/prick/environment.rb', line 119

def types
  @types
end

Instance Method Details

#bash_command(environment = nil) ⇒ Object

FIXME build has been out-commented



143
144
145
146
147
148
149
150
151
152
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/prick/environment.rb', line 143

def bash_command(environment = nil)
  raise "Not available right now"
  constrain environment, String, nil
  if environment
    env = self[environment] or raise "Unknown environment: '#{environment}'"
    envs = [env]
  else
    envs = environments
  end

  puts "### SCRIPT by #{File.basename(__FILE__)}"

  puts %(

    ## STACK METHODS - ChatGPT

    # global variable
    super_stack=()

    function push_super_stack() {
      local method=$1
      super_stack+=($method)
    }

    function pop_super_stack() {
      super_stack=("${super_stack[@]::${#super_stack[@]}-1}")
    }

    function super() {
      eval ${super_stack[-1]}
    }
  ).align

  puts "## ENVIRONMENT METHODS"
  puts
  for name, env in environments
    puts "function build_#{name}() {"
    assigner = env.assigners[:build]
    indent {
      if assigner == env
        if env.has_super?
          puts "push_super_stack #{env.super_bash}"
        end
        puts env[:build]
        if env.has_super?
          puts "pop_super_stack"
        end
      else
        puts "build_#{assigner.name} # default super"
      end
    }
    puts "}"
    puts
    if env.has_super? && assigner == env
      puts "build_#{name}_super() { build_#{env.super_environment.name}; }"
      puts
    end
  end

  if environment
    puts "## DEFAULT BUILD METHOD"
    puts
    puts "function build() { build_#{environment}; }"
    puts
  end
end

#bash_environmentObject



138
139
140
# File 'lib/prick/environment.rb', line 138

def bash_environment

end

#dumpObject



210
211
212
213
214
215
216
# File 'lib/prick/environment.rb', line 210

def dump
  puts "Types"
  indent { types.each { |k,v| puts "#{k}: #{v}" } }
  puts
  puts "Environments"
  indent { environments.values.each { |env| env.dump } }
end

#prick_variablesObject

List of variable identifiers defined by prick



125
# File 'lib/prick/environment.rb', line 125

def prick_variables = @@PRICK_VARIABLES

#user_variablesObject

List of user defined variables



128
# File 'lib/prick/environment.rb', line 128

def user_variables = variables - prick_variables

#variablesObject

List of all variables (Symbol). Same as ‘types.keys’



122
# File 'lib/prick/environment.rb', line 122

def variables = types.keys