class SqlcachedClient::Attachment

Constants

PREDICATES

Attributes

entity_class[R]
variables[R]
conditions[R]
content[RW]
name[R]

Public Class Methods

add_variable(variable_name, predicate) click to toggle source
# File lib/sqlcached_client/attachment.rb, line 22
def add_variable(variable_name, predicate)
  raise "Invalid predicate" if !PREDICATES.include?(predicate)
  @variables = [] if @variables.nil?
  @variables << OpenStruct.new(name: variable_name, predicate: predicate)
end
Also aliased as: depends_on
depends_on(variable_name, predicate)
Alias for: add_variable
new(name, conditions, content) click to toggle source

@param conditions [Hash] { var_1: 'value 1', var_2: 'value 2' }

# File lib/sqlcached_client/attachment.rb, line 12
def initialize(name, conditions, content)
  @name = name
  @conditions = conditions.with_indifferent_access
  @content = content
end

Public Instance Methods

entity_class() click to toggle source
# File lib/sqlcached_client/attachment.rb, line 35
def entity_class
  self.class.entity_class
end
entity_namespace() click to toggle source
# File lib/sqlcached_client/attachment.rb, line 39
def entity_namespace
  entity_class.try(:entity_namespace)
end
to_query_format() click to toggle source
# File lib/sqlcached_client/attachment.rb, line 43
def to_query_format
  {
    name: external_name,
    condition_values: Hash[
      variables.map { |v| [v.name, conditions[v.name]] }
    ]
  }
end
to_save_format() click to toggle source
# File lib/sqlcached_client/attachment.rb, line 52
def to_save_format
  {
    name: external_name,
    attachment: content,
    conditions: variables.map do |v|
      "#{v.name} #{v.predicate} #{conditions[v.name]}"
    end
  }
end
variables() click to toggle source
# File lib/sqlcached_client/attachment.rb, line 31
def variables
  self.class.variables
end

Private Instance Methods

external_name() click to toggle source
# File lib/sqlcached_client/attachment.rb, line 64
def external_name
  @external_name ||=
    if prefix = entity_namespace.presence
      "#{entity_namespace}::#{name}"
    else
      name
    end
end