Module: GyomuRuby::HelperUtility

Defined in:
lib/gyomu_ruby/helper_utility.rb

Instance Method Summary collapse

Instance Method Details

#human(klass, attribute = nil) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/gyomu_ruby/helper_utility.rb', line 3

def human(klass, attribute = nil)
  if attribute
    klass.human_attribute_name(attribute)
  else
    klass.model_name.human
  end
end

#nice_datetime_duration(from, to, join_word = ' - ') ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/gyomu_ruby/helper_utility.rb', line 15

def nice_datetime_duration(from, to, join_word = ' - ')
  from, to = [from, to].map(&:localtime)

  if from.localtime.to_date == to.localtime.to_date
    [l(from), to.strftime("%H:%M")]
  else
    [l(from), l(to)]
  end.join(join_word)
end

#routed_to?(*signatures) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/gyomu_ruby/helper_utility.rb', line 11

def routed_to?(*signatures)
  [controller_name, action_name].join('#').in?(Array(signatures))
end

#with_paging(objects, opts = {}, &block) ⇒ Object



25
26
27
28
# File 'lib/gyomu_ruby/helper_utility.rb', line 25

def with_paging(objects, opts = {}, &block)
  inner = capture { block.call(objects) }
  render partial: 'shared/paging', locals: {objects: objects, inner: inner, opts: opts}
end