Class: Helm::Queries::Server

Inherits:
Helm::Query show all
Defined in:
lib/helm/queries/server.rb

Instance Attribute Summary collapse

Attributes inherited from Helm::Query

#db

Instance Method Summary collapse

Methods inherited from Helm::Query

#each, #initialize, #print

Constructor Details

This class inherits a constructor from Helm::Query

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/helm/queries/server.rb', line 7

def client
  @client
end

#id_from_platformObject

Returns the value of attribute id_from_platform.



7
8
9
# File 'lib/helm/queries/server.rb', line 7

def id_from_platform
  @id_from_platform
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/helm/queries/server.rb', line 7

def name
  @name
end

#platformObject

Returns the value of attribute platform.



7
8
9
# File 'lib/helm/queries/server.rb', line 7

def platform
  @platform
end

#roleObject

Returns the value of attribute role.



7
8
9
# File 'lib/helm/queries/server.rb', line 7

def role
  @role
end

#server_idObject

Returns the value of attribute server_id.



7
8
9
# File 'lib/helm/queries/server.rb', line 7

def server_id
  @server_id
end

Instance Method Details

#constraintObject



29
30
31
# File 'lib/helm/queries/server.rb', line 29

def constraint
  @constraint ||= @db[:servers].where(constraint_hash)
end

#constraint_attrsObject



18
19
20
# File 'lib/helm/queries/server.rb', line 18

def constraint_attrs
  [:server_id, :client, :name, :role, :platform, :id_from_plaform]
end

#constraint_hashObject



22
23
24
25
26
27
# File 'lib/helm/queries/server.rb', line 22

def constraint_hash
  @constraint_hash ||= constraint_attrs.each_with_object({}) do |attr, hash|
    val = instance_variable_get("@#{attr}")
    hash[attr] = val unless val.nil?
  end
end

#inspectObject



14
15
16
# File 'lib/helm/queries/server.rb', line 14

def inspect
  "<#{self.class.name}:#{"%0x" % object_id} #{constraint.select_sql rescue "<?sql?>"}>"
end

#result_classObject



33
34
35
# File 'lib/helm/queries/server.rb', line 33

def result_class
  Records::Server
end

#to_sObject



9
10
11
12
# File 'lib/helm/queries/server.rb', line 9

def to_s
  nil_attrs = constraint_attrs.reject{|attr| constraint_hash.has_key?(attr) }
  "Servers query: #{constraint_hash.inspect} (not set: #{nil_attrs.inspect})"
end