Sha256: 2939e9e67f5df64392715166c80c7ce109cb9dbdaaae09d82f69453cd679bd59

Contents?: true

Size: 879 Bytes

Versions: 6

Compression:

Stored size: 879 Bytes

Contents

require 'sunrise/config/field'
require 'sunrise/config/nested_field'

module Sunrise
  module Config
    # Provides accessors and autoregistering of model's fields.
    module HasFields
    
      # Array for store all defined fields
      def fields
        @fields ||= []
      end
      
      # Defines a configuration for a field.
      def field(name = :custom, options = {}, &block)
        options = { :name => name.to_sym }.merge(options)
        fields << Field.new(abstract_model, self, options, &block)
      end

      # Defines a configuration for a nested attributes
      def nested_attributes(name, options = {}, &block)
        options = { :name => name.to_sym }.merge(options)
        nested_field = NestedField.new(abstract_model, self, options)
        nested_field.instance_eval &block if block
        fields << nested_field
      end
    end
  end
end   

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sunrise-cms-1.0.6 lib/sunrise/config/has_fields.rb
sunrise-cms-1.0.5 lib/sunrise/config/has_fields.rb
sunrise-cms-1.0.4 lib/sunrise/config/has_fields.rb
sunrise-cms-1.0.3 lib/sunrise/config/has_fields.rb
sunrise-cms-1.0.2 lib/sunrise/config/has_fields.rb
sunrise-cms-1.0.1 lib/sunrise/config/has_fields.rb