module Para::Generators::FieldHelpers

Private Instance Methods

attributes() click to toggle source
# File lib/para/generators/field_helpers.rb, line 6
def attributes
  @attributes ||= begin
    model = namespaced_class_name.constantize
    AttributeFieldMappings.new(model).fields
  end
end
field_options_for(field, options = {}) click to toggle source
# File lib/para/generators/field_helpers.rb, line 13
def field_options_for(field, options = {})
  field_options = field.field_options.merge(options)

  options = field_options.each_with_object([]) do |(key, value), ary|
    if writable_value?(value)
      if key.to_s.match(/^[\w\d]+/)
        join_symbol = ': '
      else
        join_symbol = ' => '
        key = key.inspect
      end

      ary << [key, join_symbol, value.inspect].join
    end
  end

  ", #{ options.join(', ') }" if options.any?
end
writable_value?(value) click to toggle source
# File lib/para/generators/field_helpers.rb, line 32
def writable_value?(value)
  [String, Symbol].any? do |type|
    value.kind_of?(type)
  end
end