Class: Devlin::Scope
- Inherits:
-
Object
- Object
- Devlin::Scope
- Defined in:
- lib/devlin/scope.rb
Defined Under Namespace
Classes: Config
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#relation ⇒ Object
Returns the value of attribute relation.
Instance Method Summary collapse
-
#add_column(name, definition, *args, &block) ⇒ Object
add a column definition to the scope.
- #column(name) ⇒ Object
- #columns ⇒ Object
-
#initialize(name, params, &block) ⇒ Scope
constructor
A new instance of Scope.
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/devlin/scope.rb', line 23 def name @name end |
#relation ⇒ Object
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 |
#columns ⇒ Object
40 41 42 43 |
# File 'lib/devlin/scope.rb', line 40 def columns @columns ||= {} @columns.keys end |