Class: Fetching

Inherits:
Object
  • Object
show all
Defined in:
lib/fetching.rb,
lib/fetching/version.rb,
lib/fetching/fetching_hash.rb,
lib/fetching/fetching_array.rb

Direct Known Subclasses

FetchingArray, FetchingHash

Defined Under Namespace

Classes: FetchingArray, FetchingHash

Constant Summary collapse

WHITELIST =
%w(
  class object_id == equal?
  define_singleton_method singleton_class
  respond_to?
  nil? tap
).freeze
VERSION =
'0.7.0'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ Fetching

Returns a new instance of Fetching.



36
37
38
# File 'lib/fetching.rb', line 36

def initialize(table)
  @table = table
end

Class Method Details

.from(value) ⇒ Object



25
26
27
28
29
30
# File 'lib/fetching.rb', line 25

def self.from(value)
  return value.to_fetching               if value.respond_to? :to_fetching
  return FetchingArray.new(value.to_ary) if value.respond_to? :to_ary
  return FetchingHash.new(value.to_hash) if value.respond_to? :to_hash
  value
end

.from_json(json) ⇒ Object



32
33
34
# File 'lib/fetching.rb', line 32

def self.from_json(json)
  from JSON.parse(json)
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
# File 'lib/fetching.rb', line 40

def ==(other)
  other.hash == hash
end

#hashObject



44
45
46
# File 'lib/fetching.rb', line 44

def hash
  self.class.hash ^ @table.hash
end

#inspectObject



56
57
58
# File 'lib/fetching.rb', line 56

def inspect
  "#<#{self.class.name}: @table=#{@table}>"
end

#to_fetchingObject



48
49
50
# File 'lib/fetching.rb', line 48

def to_fetching
  self
end

#to_sObject



52
53
54
# File 'lib/fetching.rb', line 52

def to_s
  @table.to_s
end