Class: ChefFixie::Sql::SqlTable
- Inherits:
-
Object
- Object
- ChefFixie::Sql::SqlTable
show all
- Includes:
- AuthzMapper
- Defined in:
- lib/chef_fixie_shahid/sql_objects.rb
Direct Known Subclasses
Associations, Clients, Containers, CookbookArtifacts, Cookbooks, DataBags, Environments, Groups, Invites, Nodes, Orgs, Policies, PolicyGroups, Roles, Users
Class Method Summary
collapse
Instance Method Summary
collapse
#authz_to_name, included, mapper, register, struct_to_name
Constructor Details
#initialize(tablespec = nil) ⇒ SqlTable
Returns a new instance of SqlTable.
356
357
358
359
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 356
def initialize(tablespec = nil)
ChefFixie::Sql.default_connection
@inner = tablespec || Sequel::Model(get_table)
end
|
Class Method Details
.element(name) ⇒ Object
doesn’t work yet element Org in class Orgs will fail because it can’t find Org (undefined)
416
417
418
419
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 416
def self.element(name)
fundef = "ElementType = name; def mk_element(x); #{name}.new(x); end"
class_eval(fundef)
end
|
.filter_by(*args) ⇒ Object
401
402
403
404
405
406
407
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 401
def self.filter_by(*args)
args.each do |field|
name = "by_#{field}"
fundef = "def #{name}(exp); filter_core(:#{field},exp); end"
class_eval(fundef)
end
end
|
.max_count_default ⇒ Object
344
345
346
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 344
def self.max_count_default
50
end
|
.primary(arg) ⇒ Object
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 384
def self.primary(arg)
name = :"by_#{arg}"
class_eval("def [](arg); #{name}(arg).all(1).first; end")
listfun = <<EOLF
def list(max_count=:default)
elements = all(max_count)
if elements == :too_many_results
elements
else
elements.map {|e| e.#{arg} }.sort
end
end
EOLF
class_eval(listfun)
end
|
.table(name) ⇒ Object
409
410
411
412
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 409
def self.table(name)
fundef = "def get_table; :#{name}; end"
class_eval(fundef)
end
|
Instance Method Details
#all(max_count = :default) ⇒ Object
370
371
372
373
374
375
376
377
378
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 370
def all(max_count = :default)
if max_count == :default
max_count = ChefFixie::Sql::SqlTable.max_count_default
end
if max_count != :all
return :too_many_results if inner.count > max_count
end
elements = inner.all.map { |org| mk_element(org) }
end
|
#filter_core(field, exp) ⇒ Object
366
367
368
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 366
def filter_core(field, exp)
self.class.new(inner.filter(field => exp))
end
|
#get_table ⇒ Object
348
349
350
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 348
def get_table
:unknown_table
end
|
#inner ⇒ Object
361
362
363
364
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 361
def inner
@inner
end
|
#mk_element(x) ⇒ Object
352
353
354
|
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 352
def mk_element(x)
x
end
|