Class: SqlcachedClient::Attachment
- Inherits:
-
Object
- Object
- SqlcachedClient::Attachment
- Defined in:
- lib/sqlcached_client/attachment.rb
Constant Summary collapse
- PREDICATES =
['=', '<=', '>']
Class Attribute Summary collapse
-
.variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#content ⇒ Object
Returns the value of attribute content.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .add_variable(variable_name, predicate) ⇒ Object (also: depends_on)
Instance Method Summary collapse
-
#initialize(name, conditions, content) ⇒ Attachment
constructor
A new instance of Attachment.
- #to_query_format ⇒ Object
- #to_save_format ⇒ Object
-
#variables ⇒ Object
class << self.
Constructor Details
#initialize(name, conditions, content) ⇒ Attachment
Returns a new instance of Attachment.
12 13 14 15 16 |
# File 'lib/sqlcached_client/attachment.rb', line 12 def initialize(name, conditions, content) @name = name @conditions = conditions.with_indifferent_access @content = content end |
Class Attribute Details
.variables ⇒ Object (readonly)
Returns the value of attribute variables.
20 21 22 |
# File 'lib/sqlcached_client/attachment.rb', line 20 def variables @variables end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
8 9 10 |
# File 'lib/sqlcached_client/attachment.rb', line 8 def conditions @conditions end |
#content ⇒ Object
Returns the value of attribute content.
9 10 11 |
# File 'lib/sqlcached_client/attachment.rb', line 9 def content @content end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/sqlcached_client/attachment.rb', line 8 def name @name end |
Class Method Details
.add_variable(variable_name, predicate) ⇒ Object Also known as: depends_on
22 23 24 25 26 |
# 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 |
Instance Method Details
#to_query_format ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/sqlcached_client/attachment.rb', line 35 def to_query_format { name: name, condition_values: Hash[ variables.map { |v| [v.name, conditions[v.name]] } ] } end |
#to_save_format ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/sqlcached_client/attachment.rb', line 44 def to_save_format { name: name, attachment: content, conditions: variables.map do |v| "#{v.name} #{v.predicate} #{conditions[v.name]}" end } end |
#variables ⇒ Object
class << self
31 32 33 |
# File 'lib/sqlcached_client/attachment.rb', line 31 def variables self.class.variables end |