Class: Devlin::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/devlin/scope.rb

Defined Under Namespace

Classes: Config

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params, &block) ⇒ Scope

Returns a new instance of Scope.



25
26
27
28
# File 'lib/devlin/scope.rb', line 25

def initialize(name, params, &block)
  Config.new(self, params, &block)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/devlin/scope.rb', line 23

def name
  @name
end

#relationObject

Returns the value of attribute relation.



22
23
24
# File 'lib/devlin/scope.rb', line 22

def relation
  @relation
end

Instance Method Details

#add_column(name, definition, *args, &block) ⇒ Object

add a column definition to the scope



31
32
33
34
35
36
37
38
# File 'lib/devlin/scope.rb', line 31

def add_column(name, definition, *args, &block)
  @columns ||= {}
  @columns[name.to_sym] = Column.new(name, {
    definition: definition,
    getter: block,
    scope: self
  }, *args)
end

#column(name) ⇒ Object



45
46
47
48
49
50
# File 'lib/devlin/scope.rb', line 45

def column(name)
  @columns ||= {}
  column = @columns[name.to_sym]
  raise "no column '#{name}' found" if column.blank?
  column
end

#columnsObject



40
41
42
43
# File 'lib/devlin/scope.rb', line 40

def columns
  @columns ||= {}
  @columns.keys
end