Module: Refinery::ExtensionGeneration
- Included in:
- EngineGenerator, FormGenerator
- Defined in:
- lib/refinery/extension_generation.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attributes_for_translation_table ⇒ 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
- #names_for_attr_accessible ⇒ 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 |
# File '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 => nil, :banner => 'NAMESPACE', :required => false class_option :extension, :type => :string, :default => nil, :banner => 'ENGINE', :required => false class_option :i18n, :type => :array, :default => [], :required => false, :banner => "field field", :desc => 'Indicates generated fields' remove_class_option :skip_namespace end end |
Instance Method Details
#attributes_for_translation_table ⇒ Object
59 60 61 |
# File 'lib/refinery/extension_generation.rb', line 59 def attributes_for_translation_table localized_attributes.inject([]) {|memo, attr| memo << ":#{attr.name} => :#{attr.type}"}.join(', ') end |
#extension_class_name ⇒ Object
29 30 31 |
# File 'lib/refinery/extension_generation.rb', line 29 def extension_class_name @extension_class_name ||= extension_name.camelize end |
#extension_name ⇒ Object
25 26 27 |
# File 'lib/refinery/extension_generation.rb', line 25 def extension_name @extension_name ||= [:extension].presence || singular_name end |
#extension_plural_class_name ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/refinery/extension_generation.rb', line 33 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
42 43 44 45 46 47 48 49 |
# File 'lib/refinery/extension_generation.rb', line 42 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
67 68 69 |
# File 'lib/refinery/extension_generation.rb', line 67 def image_attributes @image_attributes ||= attributes.select { |a| a.type == :image }.uniq end |
#localized? ⇒ Boolean
51 52 53 |
# File 'lib/refinery/extension_generation.rb', line 51 def localized? localized_attributes.any? end |
#localized_attributes ⇒ Object
55 56 57 |
# File 'lib/refinery/extension_generation.rb', line 55 def localized_attributes @localized_attributes ||= attributes.select{|a| [:i18n].include?(a.name)} end |
#names_for_attr_accessible ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/refinery/extension_generation.rb', line 75 def names_for_attr_accessible @attributes_for_attr_accessible ||= attributes.map do |a| case a.type when :image, :resource "#{a.name}_id" unless a.name[-3..-1] == "_id" else a.name end end end |
#namespacing ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/refinery/extension_generation.rb', line 16 def namespacing @namespacing ||= if [:namespace].present? # Use exactly what the user requested, not a pluralised version. [:namespace].to_s.camelize else class_name.pluralize end end |
#resource_attributes ⇒ Object
71 72 73 |
# File 'lib/refinery/extension_generation.rb', line 71 def resource_attributes @resource_attributes ||= attributes.select { |a| a.type == :resource }.uniq end |
#string_attributes ⇒ Object
63 64 65 |
# File 'lib/refinery/extension_generation.rb', line 63 def string_attributes @string_attributes ||= attributes.select {|a| /string|text/ === a.type.to_s}.uniq end |