Class: Bhf::Platform
- Inherits:
-
Object
- Object
- Bhf::Platform
- Defined in:
- lib/bhf/platform.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#page_name ⇒ Object
readonly
Returns the value of attribute page_name.
-
#pagination ⇒ Object
Returns the value of attribute pagination.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#title_singular ⇒ Object
readonly
Returns the value of attribute title_singular.
-
#title_zero ⇒ Object
readonly
Returns the value of attribute title_zero.
Instance Method Summary collapse
- #columns ⇒ Object
- #columns_count ⇒ Object
- #custom_columns? ⇒ Boolean
- #custom_link ⇒ Object
- #custom_partial ⇒ Object
- #custom_search ⇒ Object
- #definitions ⇒ Object
- #entries_per_page ⇒ Object
- #fields ⇒ Object
- #form ⇒ Object
- #has_file_upload? ⇒ Boolean
- #hide_create ⇒ Object
- #hide_delete ⇒ Object
- #hide_edit ⇒ Object
- #hooks(method) ⇒ Object
-
#initialize(options, page_name, user = nil) ⇒ Platform
constructor
A new instance of Platform.
- #model ⇒ Object
- #model_name ⇒ Object
- #prepare_objects(options, paginate_options = nil) ⇒ Object
- #search? ⇒ Boolean
- #search_field? ⇒ Boolean
- #search_source ⇒ Object
- #show ⇒ Object
- #show_duplicate ⇒ Object
- #show_extra_fields ⇒ Object
- #sortable ⇒ Object
- #table ⇒ Object
- #user_scope? ⇒ Boolean
Constructor Details
#initialize(options, page_name, user = nil) ⇒ Platform
Returns a new instance of Platform.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bhf/platform.rb', line 7 def initialize(, page_name, user = nil) @objects = [] if .is_a?(String) = { => nil} end @name = .keys[0] @data = .values[0] || {} @collection = get_collection t_model_path = "activerecord.models.#{model.model_name.to_s.downcase}" model_name = I18n.t(t_model_path, count: 2, default: @name.pluralize.capitalize) @title = I18n.t("bhf.platforms.#{@name}.title", count: 2, default: model_name) model_name = I18n.t(t_model_path, count: 1, default: @name.singularize.capitalize) @title_singular = I18n.t("bhf.platforms.#{@name}.title", count: 1, default: model_name) model_name = I18n.t(t_model_path, count: 0, default: @name.singularize.capitalize) @title_zero = I18n.t("bhf.platforms.#{@name}.title", count: 0, default: model_name) @page_name = page_name @user = user end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def name @name end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def objects @objects end |
#page_name ⇒ Object (readonly)
Returns the value of attribute page_name.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def page_name @page_name end |
#pagination ⇒ Object
Returns the value of attribute pagination.
4 5 6 |
# File 'lib/bhf/platform.rb', line 4 def pagination @pagination end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def title @title end |
#title_singular ⇒ Object (readonly)
Returns the value of attribute title_singular.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def title_singular @title_singular end |
#title_zero ⇒ Object (readonly)
Returns the value of attribute title_zero.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def title_zero @title_zero end |
Instance Method Details
#columns ⇒ Object
92 93 94 95 96 97 |
# File 'lib/bhf/platform.rb', line 92 def columns default_attrs((:display) || (:columns), @collection[0..5]). each_with_object([]) do |field, obj| obj << Bhf::Data::Column.new(field) end end |
#columns_count ⇒ Object
141 142 143 |
# File 'lib/bhf/platform.rb', line 141 def columns_count columns.count + (sortable ? 2 : 1) end |
#custom_columns? ⇒ Boolean
41 42 43 |
# File 'lib/bhf/platform.rb', line 41 def custom_columns? (:columns).is_a?(Array) end |
#custom_link ⇒ Object
165 166 167 |
# File 'lib/bhf/platform.rb', line 165 def custom_link 'custom_link' end |
#custom_partial ⇒ Object
169 170 171 |
# File 'lib/bhf/platform.rb', line 169 def custom_partial 'partial' end |
#custom_search ⇒ Object
37 38 39 |
# File 'lib/bhf/platform.rb', line 37 def custom_search (:custom_search) end |
#definitions ⇒ Object
99 100 101 102 103 104 |
# File 'lib/bhf/platform.rb', line 99 def definitions default_attrs((:display) || (:definitions), @collection, false). each_with_object([]) do |field, obj| obj << Bhf::Data::Show.new(field) end end |
#entries_per_page ⇒ Object
110 111 112 |
# File 'lib/bhf/platform.rb', line 110 def entries_per_page (:per_page) end |
#fields ⇒ Object
88 89 90 |
# File 'lib/bhf/platform.rb', line 88 def fields default_attrs((:display), @collection, false) end |
#form ⇒ Object
131 132 133 |
# File 'lib/bhf/platform.rb', line 131 def form @data['form'] end |
#has_file_upload? ⇒ Boolean
114 115 116 117 118 119 120 121 |
# File 'lib/bhf/platform.rb', line 114 def has_file_upload? return true if (:multipart) == true fields.each do |field| return true if field.form_type.to_sym == :file end false end |
#hide_create ⇒ Object
153 154 155 |
# File 'lib/bhf/platform.rb', line 153 def hide_create 'hide_create' end |
#hide_delete ⇒ Object
161 162 163 |
# File 'lib/bhf/platform.rb', line 161 def hide_delete 'hide_delete' end |
#hide_edit ⇒ Object
149 150 151 |
# File 'lib/bhf/platform.rb', line 149 def hide_edit 'hide_edit' end |
#hooks(method) ⇒ Object
135 136 137 138 139 |
# File 'lib/bhf/platform.rb', line 135 def hooks(method) if @data['hooks'] && @data['hooks'][method.to_s] @data['hooks'][method.to_s].to_sym end end |
#model ⇒ Object
79 80 81 82 |
# File 'lib/bhf/platform.rb', line 79 def model return @data['model'].constantize if @data['model'] @name.singularize.camelize.constantize end |
#model_name ⇒ Object
84 85 86 |
# File 'lib/bhf/platform.rb', line 84 def model_name ActiveModel::Naming.singular(model) end |
#prepare_objects(options, paginate_options = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bhf/platform.rb', line 53 def prepare_objects(, = nil) if user_scope? chain = @user.send((:user_scope).to_sym) else chain = model chain = chain.send data_source if data_source end if [:order] chain = chain.reorder("#{[:order]} #{[:direction]}") end if search? && [:search].present? chain = do_search(chain, [:search]) end if && !sortable chain = chain.page([:page]).per([:per_page]) elsif chain == model chain = chain.all end @objects = chain end |
#search? ⇒ Boolean
29 30 31 |
# File 'lib/bhf/platform.rb', line 29 def search? (:search) != false end |
#search_field? ⇒ Boolean
33 34 35 |
# File 'lib/bhf/platform.rb', line 33 def search_field? (:search_field) != false end |
#search_source ⇒ Object
49 50 51 |
# File 'lib/bhf/platform.rb', line 49 def search_source (:search) || :where end |
#show ⇒ Object
127 128 129 |
# File 'lib/bhf/platform.rb', line 127 def show @data['show'] end |
#show_duplicate ⇒ Object
157 158 159 |
# File 'lib/bhf/platform.rb', line 157 def show_duplicate 'show_duplicate' end |
#show_extra_fields ⇒ Object
106 107 108 |
# File 'lib/bhf/platform.rb', line 106 def show_extra_fields (:extra_fields) end |
#sortable ⇒ Object
145 146 147 |
# File 'lib/bhf/platform.rb', line 145 def sortable 'sortable' end |
#table ⇒ Object
123 124 125 |
# File 'lib/bhf/platform.rb', line 123 def table @data['table'] end |
#user_scope? ⇒ Boolean
45 46 47 |
# File 'lib/bhf/platform.rb', line 45 def user_scope? @user && (:user_scope) end |