Class: FormatFeature::Feature
- Inherits:
-
Object
- Object
- FormatFeature::Feature
- Defined in:
- lib/petro/format_feature.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #code ⇒ Object
- #controller_code ⇒ Object
- #controller_methods ⇒ Object
- #has_controller? ⇒ Boolean
- #has_model? ⇒ Boolean
-
#initialize(name, options) ⇒ Feature
constructor
A new instance of Feature.
- #model_code ⇒ Object
- #scaffold? ⇒ Boolean
- #scaffold_code ⇒ Object
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, ) @name = name @controller = ::Formatter::Controller.new(.fetch('controller', {})) @model = ::Formatter::Model.new(.fetch('model', {})) end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
28 29 30 |
# File 'lib/petro/format_feature.rb', line 28 def controller @controller end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
28 29 30 |
# File 'lib/petro/format_feature.rb', line 28 def model @model end |
#name ⇒ Object (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
#code ⇒ Object
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_code ⇒ Object
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_methods ⇒ Object
72 73 74 |
# File 'lib/petro/format_feature.rb', line 72 def controller_methods controller.valid_methods.join(' ') end |
#has_controller? ⇒ Boolean
40 41 42 |
# File 'lib/petro/format_feature.rb', line 40 def has_controller? @controller.has_methods? end |
#has_model? ⇒ Boolean
36 37 38 |
# File 'lib/petro/format_feature.rb', line 36 def has_model? @model.attributes.present? end |
#model_code ⇒ Object
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
44 45 46 |
# File 'lib/petro/format_feature.rb', line 44 def scaffold? has_model? && has_controller? end |
#scaffold_code ⇒ Object
54 55 56 |
# File 'lib/petro/format_feature.rb', line 54 def scaffold_code "rails g scaffold #{name.pluralize} #{model.attributes}".strip end |