class FormatFeature::Feature

Attributes

controller[R]
model[R]
name[R]

Public Class Methods

new(name, options) click to toggle source
# File lib/petro/format_feature.rb, line 29
def initialize(name, options)
  @name       = name
  @controller = ::Formatter::Controller.new(options.fetch('controller', {}))
  @model      = ::Formatter::Model.new(options.fetch('model', {}))
end

Public Instance Methods

code() click to toggle source
# File lib/petro/format_feature.rb, line 48
def code
  return scaffold_code if scaffold?
  [model_code, controller_code].compact.join(' && ')
end
controller_code() click to toggle source
# File lib/petro/format_feature.rb, line 63
def controller_code
  if controller.all_methods?
    "rails g scaffold_controller #{name.pluralize}".strip
  elsif controller.has_methods?
    "rails g controller #{name.pluralize} #{controller_methods}".strip
  end
end
controller_methods() click to toggle source
# File lib/petro/format_feature.rb, line 72
def controller_methods
  controller.valid_methods.join(' ')
end
has_controller?() click to toggle source
# File lib/petro/format_feature.rb, line 40
def has_controller?
  @controller.has_methods?
end
has_model?() click to toggle source
# File lib/petro/format_feature.rb, line 36
def has_model?
  @model.attributes.present?
end
model_code() click to toggle source
# File lib/petro/format_feature.rb, line 58
def model_code
  "rails g model #{name.singularize} #{model.attributes}".strip
end
scaffold?() click to toggle source
# File lib/petro/format_feature.rb, line 44
def scaffold?
  has_model? && has_controller?
end
scaffold_code() click to toggle source
# File lib/petro/format_feature.rb, line 54
def scaffold_code
  "rails g scaffold #{name.pluralize} #{model.attributes}".strip
end