Class: SimplyGenius::Atmos::Generator::ThorGenerator

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/simplygenius/atmos/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tmpl, parent, **opts) ⇒ ThorGenerator

Returns a new instance of ThorGenerator.



76
77
78
79
80
# File 'lib/simplygenius/atmos/generator.rb', line 76

def initialize(tmpl, parent, **opts)
  @tmpl = tmpl
  @parent = parent
  super([], **opts)
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



74
75
76
# File 'lib/simplygenius/atmos/generator.rb', line 74

def parent
  @parent
end

#tmplObject (readonly)

Returns the value of attribute tmpl.



74
75
76
# File 'lib/simplygenius/atmos/generator.rb', line 74

def tmpl
  @tmpl
end

Instance Method Details

#add_config(yml_file, key, value, additive: true) ⇒ Object



192
193
194
195
196
# File 'lib/simplygenius/atmos/generator.rb', line 192

def add_config(yml_file, key, value, additive: true)
  new_yml = SettingsHash.add_config(yml_file, key, value, additive: additive)
  create_file yml_file, new_yml
  @raw_configs.delete(yml_file) if @raw_configs
end

#agree(question, character = nil, varname: nil, &details) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'lib/simplygenius/atmos/generator.rb', line 160

def agree(question, character = nil, varname: nil, &details)
  result = lookup_context(varname)
  if result.nil?
    result = super(question, character, &details)
  end
  result = !!result
  track_context(varname, result)
  result
end

#ask(question, answer_type = nil, varname: nil, &details) ⇒ Object



150
151
152
153
154
155
156
157
# File 'lib/simplygenius/atmos/generator.rb', line 150

def ask(question, answer_type = nil, varname: nil, &details)
  result = lookup_context(varname)
  if result.nil?
    result = super(question, answer_type, &details)
  end
  track_context(varname, result)
  result
end

#choose(*items, varname: nil, &details) ⇒ Object



171
172
173
174
175
176
177
178
# File 'lib/simplygenius/atmos/generator.rb', line 171

def choose(*items, varname: nil, &details)
  result = lookup_context(varname)
  if result.nil?
    result = super(*items, &details)
  end
  track_context(varname, result)
  result
end

#config_present?(yml_file, key, value = nil) ⇒ Boolean

Returns:

  • (Boolean)


205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/simplygenius/atmos/generator.rb', line 205

def config_present?(yml_file, key, value=nil)
  val = get_config(yml_file, key)

  result = val.present?
  if value && result
    if val.is_a?(Array)
      result = Array(value).all? {|v| val.include?(v) }
    else
      result = (val == value)
    end
  end

  return result
end

#generate(name, ctx: context) ⇒ Object



181
182
183
# File 'lib/simplygenius/atmos/generator.rb', line 181

def generate(name, ctx: context)
  parent.generate(name, context: ctx.clone)
end

#get_config(yml_file, key) ⇒ Object



199
200
201
202
# File 'lib/simplygenius/atmos/generator.rb', line 199

def get_config(yml_file, key)
  config = raw_config(yml_file)
  config.notation_get(key)
end

#new_keys?(src_yml_file, dest_yml_file) ⇒ Boolean

Returns:

  • (Boolean)


221
222
223
224
225
# File 'lib/simplygenius/atmos/generator.rb', line 221

def new_keys?(src_yml_file, dest_yml_file)
  src = raw_config(src_yml_file).keys.sort
  dest = raw_config(dest_yml_file).keys.sort
  (src - dest).size > 0
end

#raw_config(yml_file) ⇒ Object



186
187
188
189
# File 'lib/simplygenius/atmos/generator.rb', line 186

def raw_config(yml_file)
  @raw_configs ||= {}
  @raw_configs[yml_file] ||= SettingsHash.new((YAML.load_file(yml_file) rescue {}))
end