Class: Bhf::Platform::Attribute::Reflection

Inherits:
Object
  • Object
show all
Defined in:
lib/bhf/platform/attribute/reflection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reflection, options = {}) ⇒ Reflection

Returns a new instance of Reflection.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bhf/platform/attribute/reflection.rb', line 6

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

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



4
5
6
# File 'lib/bhf/platform/attribute/reflection.rb', line 4

def info
  @info
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/bhf/platform/attribute/reflection.rb', line 4

def name
  @name
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/bhf/platform/attribute/reflection.rb', line 4

def title
  @title
end

Instance Method Details

#db_nameObject



58
59
60
# File 'lib/bhf/platform/attribute/reflection.rb', line 58

def db_name
  @reflection.foreign_key
end

#display_typeObject



30
31
32
# File 'lib/bhf/platform/attribute/reflection.rb', line 30

def display_type
  @options_display_type || :default
end

#form_typeObject



26
27
28
# File 'lib/bhf/platform/attribute/reflection.rb', line 26

def form_type
  type
end


66
67
68
69
# File 'lib/bhf/platform/attribute/reflection.rb', line 66

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

#macroObject



21
22
23
24
# File 'lib/bhf/platform/attribute/reflection.rb', line 21

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

#reflectionObject



54
55
56
# File 'lib/bhf/platform/attribute/reflection.rb', line 54

def reflection
  @reflection
end

#reorderbleObject



62
63
64
# File 'lib/bhf/platform/attribute/reflection.rb', line 62

def reorderble
  @reorderble
end

#show_typeObject



38
39
40
# File 'lib/bhf/platform/attribute/reflection.rb', line 38

def show_type
  @options_show_type || display_type
end

#typeObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bhf/platform/attribute/reflection.rb', line 42

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

#type_ignore_emtpy?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/bhf/platform/attribute/reflection.rb', line 34

def type_ignore_emtpy?
  false
end