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.



79
80
81
82
83
# File 'lib/simplygenius/atmos/generator.rb', line 79

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#tmplObject (readonly)

Returns the value of attribute tmpl.



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

def tmpl
  @tmpl
end

Instance Method Details

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



195
196
197
198
199
# File 'lib/simplygenius/atmos/generator.rb', line 195

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



163
164
165
166
167
168
169
170
171
# File 'lib/simplygenius/atmos/generator.rb', line 163

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



153
154
155
156
157
158
159
160
# File 'lib/simplygenius/atmos/generator.rb', line 153

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



174
175
176
177
178
179
180
181
# File 'lib/simplygenius/atmos/generator.rb', line 174

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)


208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/simplygenius/atmos/generator.rb', line 208

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



184
185
186
# File 'lib/simplygenius/atmos/generator.rb', line 184

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

#get_config(yml_file, key) ⇒ Object



202
203
204
205
# File 'lib/simplygenius/atmos/generator.rb', line 202

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)


224
225
226
227
228
# File 'lib/simplygenius/atmos/generator.rb', line 224

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



189
190
191
192
# File 'lib/simplygenius/atmos/generator.rb', line 189

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