Sha256: 3602505e5a25fc778524157e898e2107a4546a19000f2bbf685c63d093d4ba06

Contents?: true

Size: 937 Bytes

Versions: 55

Compression:

Stored size: 937 Bytes

Contents

module Para
  module Generators
    module FieldHelpers
      private

      def attributes
        @attributes ||= begin
          model = namespaced_class_name.constantize
          AttributeFieldMappings.new(model).fields
        end
      end

      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

      def writable_value?(value)
        [String, Symbol].any? do |type|
          value.kind_of?(type)
        end
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
para-0.7.3.p5 lib/para/generators/field_helpers.rb
para-0.7.3.p4 lib/para/generators/field_helpers.rb
para-0.7.3.p3 lib/para/generators/field_helpers.rb
para-0.7.3.p2 lib/para/generators/field_helpers.rb
para-0.7.3.p1 lib/para/generators/field_helpers.rb
para-0.7.3 lib/para/generators/field_helpers.rb
para-0.7.2 lib/para/generators/field_helpers.rb
para-0.7.1 lib/para/generators/field_helpers.rb
para-0.7.0 lib/para/generators/field_helpers.rb
para-0.6.9 lib/para/generators/field_helpers.rb
para-0.6.8 lib/para/generators/field_helpers.rb
para-0.6.7 lib/para/generators/field_helpers.rb
para-0.6.3 lib/para/generators/field_helpers.rb
para-0.6.2 lib/para/generators/field_helpers.rb
para-0.5.4 lib/para/generators/field_helpers.rb