Module: ActiveRecordExtension::ClassMethods

Defined in:
lib/adminpanel/active_record_extension.rb

Overview

static(class) methods

Instance Method Summary collapse

Instance Method Details

#belongs_to_relationships ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/adminpanel/active_record_extension.rb', line 92

def belongs_to_relationships
  belongs_to_classes = []
  form_attributes.each do |fields|
  fields.each do |attribute, properties|
    if properties["type"] == "belongs_to"
      belongs_to_classes << properties["model"].classify.constantize
    end
  end
  end
  return belongs_to_classes
end

#display_attributes ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/adminpanel/active_record_extension.rb', line 68

def display_attributes
  display_attributes = []
  form_attributes.each do |attribute|
    attribute.each do |name, properties|
      if properties["show"].nil? || properties["show"] == "true"
        display_attributes << attribute
      end
    end
  end

  return display_attributes
end

#display_name ⇒ Object



19
20
21
# File 'lib/adminpanel/active_record_extension.rb', line 19

def display_name
  "display_name"
end

#form_attributes ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/adminpanel/active_record_extension.rb', line 10

def form_attributes
  [{
    "name" => {
      "type" => "text_field",
      "name" => "name"
    }
  }]
end

#get_attribute_label(field) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/adminpanel/active_record_extension.rb', line 46

def get_attribute_label(field)
  form_attributes.each do |attribute|
    attribute.each do |name, properties|
      if name == field
        return properties["label"]
      end
    end
  end
  return ":("
end

#get_attribute_name(field) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/adminpanel/active_record_extension.rb', line 23

def get_attribute_name(field)
  form_attributes.each do |attribute|
    attribute.each do |name, properties|
      if name == field
        return properties["name"]
      end
    end
  end
  return ":("
end

#get_attribute_placeholder(field) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/adminpanel/active_record_extension.rb', line 57

def get_attribute_placeholder(field)
  form_attributes.each do |attribute|
    attribute.each do |name, properties|
      if name == field
        return properties["placeholder"]
      end
    end
  end
  return ":("
end

#has_images? ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
# File 'lib/adminpanel/active_record_extension.rb', line 81

def has_images?
  form_attributes.each do |fields|
  fields.each do |attribute, properties|
    if properties["type"] == "adminpanel_file_field"
      return true
    end
  end
  end
  return false
end

#has_many_relationships ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/adminpanel/active_record_extension.rb', line 104

def has_many_relationships
  has_many_classes = []
  form_attributes.each do |fields|
  fields.each do |attribute, properties|
    if properties["type"] == "has_many"
      has_many_classes << properties["model"].classify.constantize
    end
  end
  end
  return has_many_classes
end

#icon ⇒ Object



116
117
118
# File 'lib/adminpanel/active_record_extension.rb', line 116

def icon
  "icon-truck"
end