Class: Hobo::Model::ViewHints
- Inherits:
-
Object
- Object
- Hobo::Model::ViewHints
- Defined in:
- lib/hobo/model/view_hints.rb
Class Method Summary collapse
- ._name ⇒ Object
-
.children(*args) ⇒ Object
allows delayed set of children in order to avoid circular references triggered by declaring children in the model.
- .field_name ⇒ Object
- .field_names ⇒ Object
- .inline_booleans(*args) ⇒ Object
- .model ⇒ Object
-
.model_name ⇒ Object
LEGACY METHODS TO REMOVE #####.
- .model_name_plural ⇒ Object
- .paginate?(arg = nil) ⇒ Boolean
- .parent(*args) ⇒ Object
- .parent_defined(arg = nil) ⇒ Object
- .primary_children ⇒ Object
- .secondary_children ⇒ Object
- .sortable?(arg = nil) ⇒ Boolean
Class Method Details
._name ⇒ Object
83 84 85 |
# File 'lib/hobo/model/view_hints.rb', line 83 def _name @_name ||= name.sub(/Hints$/, '') end |
.children(*args) ⇒ Object
allows delayed set of children in order to avoid circular references triggered by declaring children in the model
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hobo/model/view_hints.rb', line 9 def children(*args) if args.empty? # reader if @children_args.nil? # value already set @children ||= [] else # set child_model = model.reflect_on_association(@children_args.first).klass if child_model.view_hints.parent.nil? and !child_model.view_hints.parent_defined parent = model.reverse_reflection(@children_args.first) child_model.view_hints.parent(parent.name, :undefined => true) if parent end @children = @children_args @children_args = nil @children end else # writer (only stores the args for delayed setting) @children_args = args end end |
.field_name ⇒ Object
110 111 112 |
# File 'lib/hobo/model/view_hints.rb', line 110 def field_name(*) raise NotImplementedError, "ViewHints.field_name is no longer supported, please use model..human_attribute_name and set a the activerecord.attributes.<model_name>.<field_name> key in a locale file" end |
.field_names ⇒ Object
114 115 116 |
# File 'lib/hobo/model/view_hints.rb', line 114 def field_names(*) raise NotImplementedError, "ViewHints.field_names is no longer supported, please set the activerecord.attributes.<model_name>.<field_name> keys in a locale file" end |
.inline_booleans(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hobo/model/view_hints.rb', line 28 def inline_booleans(*args) if args.empty? # reader if @inline_booleans_args.nil? @inline_booleans ||= [] else @inline_booleans = if @inline_booleans_args.first == true model.columns.select { |c| c.type == :boolean }.*.name else @inline_booleans_args.*.to_s end @inline_booleans_args = nil @inline_booleans end else # writer @inline_booleans_args = args end end |
.model ⇒ Object
87 88 89 |
# File 'lib/hobo/model/view_hints.rb', line 87 def model @model ||= _name.constantize end |
.model_name ⇒ Object
LEGACY METHODS TO REMOVE #####
102 103 104 |
# File 'lib/hobo/model/view_hints.rb', line 102 def model_name(*) raise NotImplementedError, "ViewHints.model_name is no longer supported, please use model.model_name.human and set a the activerecord.models.<model_name> key in a locale file" end |
.model_name_plural ⇒ Object
106 107 108 |
# File 'lib/hobo/model/view_hints.rb', line 106 def model_name_plural(*) raise NotImplementedError, "ViewHints.model_name_plural is no longer supported, please use model.model_name.human(:count => n) and set a the activerecord.models.<model_name> key in a locale file" end |
.paginate?(arg = nil) ⇒ Boolean
64 65 66 67 68 69 70 |
# File 'lib/hobo/model/view_hints.rb', line 64 def paginate?(arg=nil) if arg.nil? @paginate ||= !sortable? else @paginate = arg end end |
.parent(*args) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/hobo/model/view_hints.rb', line 46 def parent(*args) if args.empty? #reader @parent else # writer = args. parent_defined(true) unless [:undefined] @parent = args.first end end |
.parent_defined(arg = nil) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/hobo/model/view_hints.rb', line 56 def parent_defined(arg=nil) if arg.nil? @parent_defined else @parent_defined = arg end end |
.primary_children ⇒ Object
91 92 93 |
# File 'lib/hobo/model/view_hints.rb', line 91 def primary_children children.first end |
.secondary_children ⇒ Object
95 96 97 |
# File 'lib/hobo/model/view_hints.rb', line 95 def secondary_children children.rest end |
.sortable?(arg = nil) ⇒ Boolean
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hobo/model/view_hints.rb', line 72 def sortable?(arg=nil) if arg.nil? @sortable ||= defined?(ActiveRecord::Acts::List::InstanceMethods) && model < ActiveRecord::Acts::List::InstanceMethods && model.table_exists? && model.new.try.scope_condition == "1 = 1" else @sortable = arg end end |