Sha256: 288d3809217c0d6d4e5ba012a85b6d550990c40c22c0eef6f2d3d3106ad917d4

Contents?: true

Size: 860 Bytes

Versions: 4

Compression:

Stored size: 860 Bytes

Contents

# -*- encoding : utf-8 -*-
module RademadeAdmin
  module Model
    class Info
      class DataItem
        class Initializer

          def auto
            return from_relation if @relation
            return form_field if @field
            raise 'No relation and field given for DateItem initialization' # TODO custom exception
          end

          def from_relation
            build(@relation.name, @relation.foreign_key)
          end

          def form_field
            name = @field.name
            build(name, name)
          end

          def build(name, order_column)
            RademadeAdmin::Model::Info::DataItem.new(name, @field, @relation, order_column)
          end

          protected

          def initialize(field, relation)
            @field, @relation = field, relation
          end

        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rademade_admin-0.2.2 lib/rademade_admin/model/info/data_item/initializer.rb
rademade_admin-0.2.1 lib/rademade_admin/model/info/data_item/initializer.rb
rademade_admin-0.2.0 lib/rademade_admin/model/info/data_item/initializer.rb
rademade_admin-0.1.6 lib/rademade_admin/model/info/data_item/initializer.rb