Class: Rediline::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/rediline/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, queries = {}) ⇒ Entry

Returns a new instance of Entry.



9
10
11
12
# File 'lib/rediline/entry.rb', line 9

def initialize(content, queries={})
  @content, @queries = parse(content), queries
  @objects = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/rediline/entry.rb', line 18

def method_missing(name, *args)
  return content[name] if content.include?(name)
  if content.include?(:"#{name}_object") && content.include?(:"#{name}_object")
    return @objects[name] ||= find_query(name, content[:"#{name}_id"])
  end
  super
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/rediline/entry.rb', line 7

def content
  @content
end

#queriesObject (readonly)

Returns the value of attribute queries.



7
8
9
# File 'lib/rediline/entry.rb', line 7

def queries
  @queries
end

Instance Method Details

#respond_to?(name, *args) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/rediline/entry.rb', line 26

def respond_to?(name, *args)
  return true if content.include?(name.to_s)
  return true if content.include?("#{name}_object") && content.include?("#{name}_object")
  super
end

#to_jsonObject



14
15
16
# File 'lib/rediline/entry.rb', line 14

def to_json
  @content.to_json
end