Sha256: 00c773555a7c6fb435b4c1719bef580042ec9bb5412ffb23187680fc0a8f85df

Contents?: true

Size: 1.53 KB

Versions: 19

Compression:

Stored size: 1.53 KB

Contents

module Bhf::Platform::Attribute
  class Reflection

    attr_reader :name, :title, :info

    def initialize(reflection, options = {})
      @name = reflection.name.to_s
      @title = options[:title]
      @info = options[:info]
      @reflection = reflection

      @options_form_type = options[:form_type].to_sym if options[:form_type]
      @options_display_type = options[:display_type].to_sym if options[:display_type]
      @options_show_type = options[:show_type].to_sym if options[:show_type]

      @link_platform_settings = options[:link] unless options[:link].blank?

      @reorderble = options[:reorderble]
    end

    def macro
      return :has_and_belongs_to_many if @reflection.macro == :has_many && @reflection.options[:through]
      @reflection.macro
    end

    def form_type
      type
    end

    def display_type
      @options_display_type || :default
    end

    def type_ignore_emtpy?
      false
    end

    def show_type
      @options_show_type || display_type
    end

    def type
      return @options_form_type if @options_form_type

      if macro == :has_and_belongs_to_many or macro == :has_many
        :check_box
      elsif macro == :belongs_to or macro == :has_one
        :select
      else
        :static
      end
    end

    def reflection
      @reflection
    end

    def db_name
      @reflection.foreign_key
    end

    def reorderble
      @reorderble
    end

    def link
      return unless @link_platform_settings
      @link ||= Bhf::Platform::Base.new(@link_platform_settings)
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bhf-1.0.0.beta16 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta15 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta14 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta13 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta12 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta11 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta10 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta9 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta8 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta7 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta6 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta5 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta4 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta3 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta2 lib/bhf/platform/attribute/reflection.rb
bhf-1.0.0.beta1 lib/bhf/platform/attribute/reflection.rb
bhf-0.10.17 lib/bhf/platform/attribute/reflection.rb
bhf-0.10.16 lib/bhf/platform/attribute/reflection.rb
bhf-0.10.15 lib/bhf/platform/attribute/reflection.rb