# File lib/smooth_operator/helpers.rb, line 11 def primary_key(object) object.internal_data_get(object.class.primary_key) end
module SmoothOperator::Helpers
Public Instance Methods
absolute_path?(string)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 76 def absolute_path?(string) present?(string) && string[0] == '/' end
blank?(object)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 61 def blank?(object) case object when String object.to_s == '' when Array, Hash object.empty? else object.nil? end end
duplicate(object)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 57 def duplicate(object) object.dup rescue object end
generated_id()
click to toggle source
# File lib/smooth_operator/helpers.rb, line 7 def generated_id Time.now.to_f.to_s.split('.')[1] end
get_instance_variable(object, variable, default_value)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 25 def get_instance_variable(object, variable, default_value) instance_var = object.instance_variable_get("@#{variable}") return instance_var unless instance_var.nil? instance_var = (super_method(object, variable) || default_value) if instance_var.class == Class object.instance_variable_set("@#{variable}", instance_var) else object.instance_variable_set("@#{variable}", duplicate(instance_var)) end end
has_primary_key?(object)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 15 def has_primary_key?(object) blank? primary_key(object) end
plural?(string)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 52 def plural?(string) string = string.to_s string == string.pluralize end
present?(object)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 72 def present?(object) !blank?(object) end
primary_key(object)
click to toggle source
remove_initial_slash(string)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 80 def remove_initial_slash(string) string[1..-1] end
stringify_keys(hash)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 39 def stringify_keys(hash) stringified_hash = {} hash.keys.each { |key| stringified_hash[key.to_s] = hash[key] } stringified_hash end
super_method(object, method_name, *args)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 19 def super_method(object, method_name, *args) if object.superclass.respond_to?(method_name) object.superclass.send(method_name, *args) end end
symbolyze_keys(hash)
click to toggle source
# File lib/smooth_operator/helpers.rb, line 45 def symbolyze_keys(hash) hash.keys.reduce({}) do |cloned_hash, key| cloned_hash[key.to_sym] = hash[key] cloned_hash end end