module Organism::GeneratorHelper

Private Instance Methods

action?(action) click to toggle source
# File lib/organism/generators/generator_helper.rb, line 102
def action?(action)
  actions.include?(action)
end
contract_class(action) click to toggle source
# File lib/organism/generators/generator_helper.rb, line 9
def contract_class(action)
  model_class_path.concat(['contracts', action]).map(&:camelize).join('::')
end
controller_class_name() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 5
def controller_class_name
  file_name.pluralize.camelize
end
create?() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 78
def create?
  action?('new') || action?('create')
end
destroy?() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 98
def destroy?
  action?('destroy')
end
edit?() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 90
def edit?
  action?('edit')
end
index?() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 86
def index?
  action?('index')
end
model_class() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 60
def model_class
  options[:model].blank? ? file_name.singularize.camelize : options[:model]
end
model_class_path() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 52
def model_class_path
  class_path + [file_name.singularize]
end
namespaced_model_class() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 48
def namespaced_model_class
  model_class_path.map!(&:camelize).join('::')
end
nest_content(content) click to toggle source
# File lib/organism/generators/generator_helper.rb, line 19
def nest_content(content)
  class_path.each do |namespace|
    constant = namespace.camelize
    begin
      content = wrap_namespace(indent(content), constant.constantize)
    rescue NameError
      content = wrap_namespace(indent(content), constant)
    end
  end

  content
end
nested_namespace(&block) click to toggle source
# File lib/organism/generators/generator_helper.rb, line 13
def nested_namespace(&block)
  content = capture(&block)
  content = nest_content(content)
  concat(content)
end
new?() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 74
def new?
  action?('new')
end
show?() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 82
def show?
  action?('show')
end
singular_actions() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 64
def singular_actions
  actions.select do |action|
    %w[show destroy edit update].include?(action)
  end
end
singular_actions?() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 70
def singular_actions?
  singular_actions.any?
end
singular_file_name() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 56
def singular_file_name
  file_name.singularize
end
update?() click to toggle source
# File lib/organism/generators/generator_helper.rb, line 94
def update?
  action?('edit') || action?('update')
end
wrap_model(content) click to toggle source
# File lib/organism/generators/generator_helper.rb, line 32
def wrap_model(content)
  "class #{model_class} < ApplicationRecord\n#{content}\nend"
end
wrap_namespace(content, namespace) click to toggle source
# File lib/organism/generators/generator_helper.rb, line 36
def wrap_namespace(content, namespace)
  return "module #{namespace}\n#{content}\nend" if namespace.is_a? String

  superclass = namespace.superclass
  case superclass
  when Object
    "class #{key}\n#{content}\nend"
  else
    "class #{key} < #{superclass}\n#{content}\nend"
  end
end