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.
Instance Method Summary collapse
- #columns ⇒ Object
- #columns_count ⇒ Object
- #custom_columns? ⇒ Boolean
- #entries_per_page ⇒ Object
- #fields ⇒ Object
- #form ⇒ Object
- #has_file_upload? ⇒ Boolean
- #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_source ⇒ 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 |
# 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 human_title = if model.to_s == @name.singularize.camelize model.model_name.human else @name.humanize end @title = I18n.t("bhf.platforms.#{@name}.title", :platform_title => human_title, :default => human_title).pluralize @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 |
Instance Method Details
#columns ⇒ Object
84 85 86 87 88 89 |
# File 'lib/bhf/platform.rb', line 84 def columns default_attrs((:columns), @collection[0..5]). each_with_object([]) do |field, obj| obj << Bhf::Data::Column.new(field) end end |
#columns_count ⇒ Object
116 117 118 |
# File 'lib/bhf/platform.rb', line 116 def columns_count columns.count + (sortable ? 2 : 1) end |
#custom_columns? ⇒ Boolean
32 33 34 |
# File 'lib/bhf/platform.rb', line 32 def custom_columns? (:columns).is_a?(Array) end |
#entries_per_page ⇒ Object
91 92 93 |
# File 'lib/bhf/platform.rb', line 91 def entries_per_page (:per_page) end |
#fields ⇒ Object
80 81 82 |
# File 'lib/bhf/platform.rb', line 80 def fields default_attrs((:display), @collection, false) end |
#form ⇒ Object
106 107 108 |
# File 'lib/bhf/platform.rb', line 106 def form @data['form'] end |
#has_file_upload? ⇒ Boolean
95 96 97 98 99 100 |
# File 'lib/bhf/platform.rb', line 95 def has_file_upload? @collection.each do |field| return true if field.form_type == :file end false end |
#hooks(method) ⇒ Object
110 111 112 113 114 |
# File 'lib/bhf/platform.rb', line 110 def hooks(method) if @data['hooks'] && @data['hooks'][method.to_s] @data['hooks'][method.to_s].to_sym end end |
#model ⇒ Object
71 72 73 74 |
# File 'lib/bhf/platform.rb', line 71 def model return @data['model'].constantize if @data['model'] @name.singularize.camelize.constantize end |
#model_name ⇒ Object
76 77 78 |
# File 'lib/bhf/platform.rb', line 76 def model_name ActiveModel::Naming.singular(model) end |
#prepare_objects(options, paginate_options = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bhf/platform.rb', line 44 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.except(:order).order("#{[:order]} #{[:direction]}") end if search? && [:search].present? chain = do_search(chain, [:search]) end if && !sortable chain = chain.paginate() end if chain == model chain = chain.all end @objects = chain end |
#search? ⇒ Boolean
28 29 30 |
# File 'lib/bhf/platform.rb', line 28 def search? (:search) != false end |
#search_source ⇒ Object
40 41 42 |
# File 'lib/bhf/platform.rb', line 40 def search_source (:search) || :where end |
#sortable ⇒ Object
120 121 122 |
# File 'lib/bhf/platform.rb', line 120 def sortable 'sortable' end |
#table ⇒ Object
102 103 104 |
# File 'lib/bhf/platform.rb', line 102 def table @data['table'] end |
#user_scope? ⇒ Boolean
36 37 38 |
# File 'lib/bhf/platform.rb', line 36 def user_scope? @user && (:user_scope) end |