Module: Refinery::ExtensionGeneration
- Included in:
- EngineGenerator
- Defined in:
- core/lib/refinery/extension_generation.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attributes_for_translation_table ⇒ Object
- #extension_authors ⇒ Object
- #extension_class_name ⇒ Object
- #extension_name ⇒ Object
- #extension_plural_class_name ⇒ Object
- #extension_plural_name ⇒ Object
- #image_attributes ⇒ Object
- #localized? ⇒ Boolean
- #localized_attributes ⇒ Object
- #localized_table_name ⇒ Object
- #namespacing ⇒ Object
- #resource_attributes ⇒ Object
- #string_attributes ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'core/lib/refinery/extension_generation.rb', line 4 def self.included(base) base.class_eval do argument :attributes, type: :array, default: [], banner: 'field:type field:type' class_option :namespace, type: :string, default: '', banner: 'NAMESPACE', required: false class_option :authors, type: :array, default: [], banner: 'author author', required: false, desc: 'Indicates authors of this extension' class_option :extension, type: :string, default: '', banner: 'ENGINE', required: false class_option :i18n, type: :array, default: [], required: false, banner: 'field field', desc: 'Indicates generated fields' class_option :install, type: :boolean, default: false, required: false, banner: nil, desc: 'Bundles and runs the generated generator, rake db:migrate, rake db:seed for you' remove_class_option :skip_namespace end end |
Instance Method Details
#attributes_for_translation_table ⇒ Object
108 109 110 |
# File 'core/lib/refinery/extension_generation.rb', line 108 def attributes_for_translation_table localized_attributes.inject([]) { |memo, attr| memo << ":#{attr.name} => :#{attr.type}"}.join(', ') end |
#extension_authors ⇒ Object
67 68 69 |
# File 'core/lib/refinery/extension_generation.rb', line 67 def @extension_authors ||= [:authors].presence end |
#extension_class_name ⇒ Object
71 72 73 |
# File 'core/lib/refinery/extension_generation.rb', line 71 def extension_class_name @extension_class_name ||= extension_name.camelize end |
#extension_name ⇒ Object
63 64 65 |
# File 'core/lib/refinery/extension_generation.rb', line 63 def extension_name @extension_name ||= [:extension].presence || singular_name end |
#extension_plural_class_name ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'core/lib/refinery/extension_generation.rb', line 75 def extension_plural_class_name @extension_plural_class_name ||= if [:extension].present? # Use exactly what the user requested, not a plural version. extension_class_name else extension_class_name.pluralize end end |
#extension_plural_name ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'core/lib/refinery/extension_generation.rb', line 84 def extension_plural_name @extension_plural_name ||= if [:extension].present? # Use exactly what the user requested, not a plural version. extension_name else extension_name.pluralize end end |
#image_attributes ⇒ Object
116 117 118 |
# File 'core/lib/refinery/extension_generation.rb', line 116 def image_attributes @image_attributes ||= attributes.select { |a| a.refinery_type == :image }.uniq end |
#localized? ⇒ Boolean
93 94 95 |
# File 'core/lib/refinery/extension_generation.rb', line 93 def localized? localized_attributes.any? end |
#localized_attributes ⇒ Object
97 98 99 |
# File 'core/lib/refinery/extension_generation.rb', line 97 def localized_attributes @localized_attributes ||= attributes.select{ |a| [:i18n].include?(a.name)} end |
#localized_table_name ⇒ Object
101 102 103 104 105 106 |
# File 'core/lib/refinery/extension_generation.rb', line 101 def localized_table_name localized_table_name = [ 'refinery'] localized_table_name << namespacing.underscore if table_name != namespacing.underscore.pluralize localized_table_name << [ singular_table_name, 'translations'] localized_table_name.join('_') end |
#namespacing ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'core/lib/refinery/extension_generation.rb', line 48 def namespacing @namespacing ||= if [:namespace].present? # Use exactly what the user requested, not a pluralised version. [:namespace].to_s.camelize else # If the user has passed an engine, we want to generate it inside of # that extension. if [:extension].present? [:extension].to_s.camelize else class_name.pluralize end end end |
#resource_attributes ⇒ Object
120 121 122 |
# File 'core/lib/refinery/extension_generation.rb', line 120 def resource_attributes @resource_attributes ||= attributes.select { |a| a.refinery_type == :resource }.uniq end |
#string_attributes ⇒ Object
112 113 114 |
# File 'core/lib/refinery/extension_generation.rb', line 112 def string_attributes @string_attributes ||= attributes.select { |a| /string|text/ === a.refinery_type.to_s}.uniq end |