Module: RTrail::Helpers

Included in:
Entity
Defined in:
lib/rtrail/helpers.rb

Defined Under Namespace

Modules: ClassMethods, HasCreateTime

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Allow include to pull in both class and instance methods



8
9
10
# File 'lib/rtrail/helpers.rb', line 8

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#is_id?(name_or_id) ⇒ Boolean

Return true if name_or_id appears to be a numeric id, false otherwise.

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/rtrail/helpers.rb', line 30

def is_id?(name_or_id)
  # Use !! to convert regex comparison to boolean
  return !!(name_or_id.to_s =~ /^[0-9]+$/)
end

#path_with_params(path, params = {}) ⇒ Object

Return an HTTP path with parameters appended in GET syntax.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rtrail/helpers.rb', line 36

def path_with_params(path, params={})
  if params.empty?
    return path
  else
    # FIXME: What if value contains a space?
    param_string = params.map do |k,v|
      "#{k}=#{v}"
    end.join("&")
    return path + "&" + param_string
  end
end