module SmoothOperator
Constants
- VERSION
Public Class Methods
included(base)
click to toggle source
# File lib/smooth_operator/attribute_assignment.rb, line 64 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
after_initialize(attributes, options)
click to toggle source
# File lib/smooth_operator/attribute_assignment.rb, line 52 def after_initialize(attributes, options); end
allowed_attribute(attribute)
click to toggle source
# File lib/smooth_operator/attribute_assignment.rb, line 54 def allowed_attribute(attribute) if !self.class.attributes_white_list.empty? self.class.attributes_white_list.include?(attribute) elsif !self.class.attributes_black_list.empty? !self.class.attributes_black_list.include?(attribute) else true end end
before_initialize(attributes, options)
click to toggle source
# File lib/smooth_operator/attribute_assignment.rb, line 50 def before_initialize(attributes, options); end
convert(value, type)
click to toggle source
# File lib/smooth_operator/type_casting.rb, line 45 def convert(value, type) case type when :string, :text, String value.to_s when :int, :integer, Integer, Fixnum to_int(value) when :date, Date to_date(value) when :float, Float to_float(value) when :bool, :boolean to_boolean(value) when :datetime, :date_time, DateTime to_datetime(value) else Helpers.duplicate(value) end end
new_unknown_hash(hash, unknown_hash_class, parent_object)
click to toggle source
# File lib/smooth_operator/type_casting.rb, line 105 def new_unknown_hash(hash, unknown_hash_class, parent_object) if unknown_hash_class.nil? hash else unknown_hash_class.new(cast_params(hash, unknown_hash_class, parent_object)) end end
resource_data_for_server(data, options)
click to toggle source
# File lib/smooth_operator/persistence.rb, line 93 def resource_data_for_server(data, options) data ||= {} options ||= {} resource_data = self.class.get_option(:resource_data_for_server, false, data, options) if resource_data == false data = Helpers.stringify_keys(data) resource_data = Helpers.stringify_keys(internal_data_for_server) resource_name = options[:resource_name] || self.class.resource_name.to_s if Helpers.present?(resource_name) { resource_name => resource_data }.merge(data) else resource_data.merge(data) end else resource_data end end
to_boolean(string)
click to toggle source
# File lib/smooth_operator/type_casting.rb, line 83 def to_boolean(string) value = string.to_s.downcase TRUE_VALUES.include?(value) ? true : FALSE_VALUES.include?(value) ? false : nil end
to_date(string)
click to toggle source
# File lib/smooth_operator/type_casting.rb, line 71 def to_date(string) return string if string.is_a?(Date) Date.parse(string) rescue nil end
to_datetime(string)
click to toggle source
# File lib/smooth_operator/type_casting.rb, line 77 def to_datetime(string) return string if string.is_a?(DateTime) DateTime.parse(string) rescue nil end
to_float(string)
click to toggle source
# File lib/smooth_operator/type_casting.rb, line 95 def to_float(string) return string if string.is_a?(Float) return 0 if string.nil? || !(string.is_a?(String) || string.is_a?(Fixnum)) value = string.to_s.gsub(',', '.').scan(/-*\d+[.]*\d*/).flatten.map(&:to_f).first value.nil? ? 0 : value end
to_int(string)
click to toggle source
# File lib/smooth_operator/type_casting.rb, line 89 def to_int(string) return string if string.is_a?(Fixnum) to_float(string).to_i end
url(options, relative_path)
click to toggle source
# File lib/smooth_operator/operators/typhoeus.rb, line 76 def url(options, relative_path) url = options[:endpoint] slice = url[-1] != '/' ? '/' : '' url = "#{url}#{slice}#{relative_path}" if Helpers.present?(relative_path) end
validate_nested_objects()
click to toggle source
# File lib/smooth_operator.rb, line 92 def validate_nested_objects all_nested_objects = self.class.reflections.keys .map { |association| send(association) }.flatten.compact all_nested_objects.map { |nested_object| nested_object.valid? }.all? end