Class: FormatFeature::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/petro/format_feature.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Feature

Returns a new instance of Feature.



29
30
31
32
33
# 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

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



28
29
30
# File 'lib/petro/format_feature.rb', line 28

def controller
  @controller
end

#modelObject (readonly)

Returns the value of attribute model.



28
29
30
# File 'lib/petro/format_feature.rb', line 28

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/petro/format_feature.rb', line 28

def name
  @name
end

Instance Method Details

#codeObject



48
49
50
51
# File 'lib/petro/format_feature.rb', line 48

def code
  return scaffold_code if scaffold?
  [model_code, controller_code].compact.join(' && ')
end

#controller_codeObject



63
64
65
66
67
68
69
# 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_methodsObject



72
73
74
# File 'lib/petro/format_feature.rb', line 72

def controller_methods
  controller.valid_methods.join(' ')
end

#has_controller?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/petro/format_feature.rb', line 40

def has_controller?
  @controller.has_methods?
end

#has_model?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/petro/format_feature.rb', line 36

def has_model?
  @model.attributes.present?
end

#model_codeObject



58
59
60
# File 'lib/petro/format_feature.rb', line 58

def model_code
  "rails g model #{name.singularize} #{model.attributes}".strip
end

#scaffold?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/petro/format_feature.rb', line 44

def scaffold?
  has_model? && has_controller?
end

#scaffold_codeObject



54
55
56
# File 'lib/petro/format_feature.rb', line 54

def scaffold_code
  "rails g scaffold #{name.pluralize} #{model.attributes}".strip
end