module ActiveObject::Object
Public Instance Methods
array?()
click to toggle source
# File lib/active_object/object.rb, line 12 def array? is_a?(Array) end
blank?()
click to toggle source
# File lib/active_object/object.rb, line 16 def blank? object = self object = object.strip if respond_to?(:strip) respond_to?(:empty?) ? object.empty? : !object end
bool?()
click to toggle source
# File lib/active_object/object.rb, line 22 def bool? true? || false? end
boolean?()
click to toggle source
# File lib/active_object/object.rb, line 26 def boolean? TRUE_VALUES.include?(self) || FALSE_VALUES.include?(self) end
date?()
click to toggle source
# File lib/active_object/object.rb, line 30 def date? is_a?(Date) end
false?()
click to toggle source
rubocop:disable Style/YodaCondition
# File lib/active_object/object.rb, line 35 def false? false == self end
falsey?()
click to toggle source
rubocop:enable Style/YodaCondition
# File lib/active_object/object.rb, line 40 def falsey? nil? || FALSE_VALUES.include?(self) end
float?()
click to toggle source
# File lib/active_object/object.rb, line 44 def float? is_a?(Float) end
hash?()
click to toggle source
# File lib/active_object/object.rb, line 48 def hash? is_a?(Hash) end
integer?()
click to toggle source
# File lib/active_object/object.rb, line 52 def integer? is_a?(Integer) end
numeral?()
click to toggle source
# File lib/active_object/object.rb, line 56 def numeral? !to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/).nil? end
numeric?()
click to toggle source
# File lib/active_object/object.rb, line 60 def numeric? is_a?(Numeric) end
palindrome?()
click to toggle source
# File lib/active_object/object.rb, line 64 def palindrome? to_s == to_s.reverse end
present?()
click to toggle source
# File lib/active_object/object.rb, line 68 def present? !blank? end
range?()
click to toggle source
# File lib/active_object/object.rb, line 72 def range? is_a?(Range) end
safe_call(*keys)
click to toggle source
# File lib/active_object/object.rb, line 76 def safe_call(*keys) try_call(*keys) || self end
safe_send(*keys)
click to toggle source
# File lib/active_object/object.rb, line 80 def safe_send(*keys) try_send(*keys) || self end
safe_try(*obj, &block)
click to toggle source
# File lib/active_object/object.rb, line 84 def safe_try(*obj, &block) try(*obj, &block) || self end
salvage(placeholder = '---')
click to toggle source
# File lib/active_object/object.rb, line 88 def salvage(placeholder = '---') blank? ? placeholder : self end
send_chain(*keys)
click to toggle source
# File lib/active_object/object.rb, line 92 def send_chain(*keys) Array(keys).inject(self) { |obj, key| obj.send(*key) } end
send_chain_if(*keys)
click to toggle source
# File lib/active_object/object.rb, line 96 def send_chain_if(*keys) Array(keys).inject(self) { |obj, key| obj.send_if(*key) } end
send_if(key, *args)
click to toggle source
# File lib/active_object/object.rb, line 100 def send_if(key, *args) return self unless respond_to?(key) send(key, *args) end
string?()
click to toggle source
# File lib/active_object/object.rb, line 106 def string? is_a?(String) end
symbol?()
click to toggle source
# File lib/active_object/object.rb, line 110 def symbol? is_a?(Symbol) end
time?()
click to toggle source
# File lib/active_object/object.rb, line 114 def time? is_a?(Time) end
true?()
click to toggle source
rubocop:disable Style/YodaCondition
# File lib/active_object/object.rb, line 119 def true? true == self end
truthy?()
click to toggle source
rubocop:enable Style/YodaCondition
# File lib/active_object/object.rb, line 124 def truthy? TRUE_VALUES.include?(self) end
try(*obj, &block)
click to toggle source
# File lib/active_object/object.rb, line 128 def try(*obj, &block) try!(*obj, &block) if obj.empty? || respond_to?(obj.first) end
try!(*obj) { |self| ... }
click to toggle source
# File lib/active_object/object.rb, line 132 def try!(*obj, &block) if obj.empty? && block_given? block.arity.zero? ? instance_eval(&block) : yield(self) else public_send(*obj, &block) end end
try_call(*keys)
click to toggle source
# File lib/active_object/object.rb, line 140 def try_call(*keys) return unless respond_to?(:call) keys.blank? ? call : call(*keys) end
try_send(*keys)
click to toggle source
# File lib/active_object/object.rb, line 146 def try_send(*keys) send(*keys) rescue nil end