class IamSure
Public Class Methods
new(obj)
click to toggle source
# File lib/iamsure.rb, line 9 def initialize(obj) @obj = obj end
of(obj)
click to toggle source
# File lib/iamsure.rb, line 13 def self.of(obj) new(obj) end
Public Instance Methods
exist(as=:file)
click to toggle source
# File lib/iamsure.rb, line 27 def exist(as=:file) raise ArgumentError.new 'Argument cannot be nil' if as.nil? raise ArgumentError.new "Argument should be Hash as 'as: :file' or 'as: :dir'" if not as.is_a?(Hash) if as.has_key?(:as) && as[:as] == :file raise ArgumentError.new "File (#{ @obj }) does not exist!" if not File.file?(@obj) elsif as.has_key?(:as) && as[:as] == :dir raise ArgumentError.new "Dir (#{ @obj }) does not exist!" if not File.directory?(@obj) else raise ArgumentError.new "Argument (#{ as }) is not valid!" end self end
get(initiator=nil)
click to toggle source
# File lib/iamsure.rb, line 50 def get(initiator=nil) return @obj if initiator.nil? return initiator.init(@obj) if initiator.is_a?(Iamsure::Initiator) raise ArgumentError.new "initiator should be empty or inherited from Initiator" end
not_empty(msg='')
click to toggle source
# File lib/iamsure.rb, line 22 def not_empty(msg='') raise ArgumentError.new msg if @obj.nil? || @obj.empty? self end
not_nil(msg='')
click to toggle source
# File lib/iamsure.rb, line 17 def not_nil(msg='') raise ArgumentError.new msg if @obj.nil? self end
unpack(unpacker)
click to toggle source
# File lib/iamsure.rb, line 41 def unpack(unpacker) raise ArgumentError.new "Argument cannot be nil!" if unpacker.nil? raise ArgumentError.new "Argument should be Unpacker!" unless unpacker.is_a?(Iamsure::Unpacker) @obj = unpacker.unpack(@obj) self end