Class: Scopedog::RecordClass
- Inherits:
-
Object
- Object
- Scopedog::RecordClass
- Defined in:
- lib/scopedog/record_class.rb
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#ar_class ⇒ Class<ActiveRecord::Base>
readonly
The current value of ar_class.
-
#yard_obj ⇒ YARD::CodeObjects::ClassObject
readonly
The current value of yard_obj.
Class Method Summary collapse
Instance Method Summary collapse
- #default_sql ⇒ String
- #docstring ⇒ String
-
#initialize(yard_obj, ar_class, root_const: Object) ⇒ RecordClass
constructor
A new instance of RecordClass.
- #name ⇒ String
- #scopes ⇒ Array<YARD::CodeObjects::MethodObject>
- #table_name ⇒ String
- #unscoped_sql ⇒ String
Constructor Details
#initialize(yard_obj, ar_class, root_const: Object) ⇒ RecordClass
Returns a new instance of RecordClass.
22 23 24 25 26 |
# File 'lib/scopedog/record_class.rb', line 22 def initialize(yard_obj, ar_class, root_const: Object) @yard_obj = yard_obj @ar_class = ar_class @root_const = root_const end |
Instance Attribute Details
#ar_class ⇒ Class<ActiveRecord::Base> (readonly)
Returns the current value of ar_class.
6 7 8 |
# File 'lib/scopedog/record_class.rb', line 6 def ar_class @ar_class end |
#yard_obj ⇒ YARD::CodeObjects::ClassObject (readonly)
Returns the current value of yard_obj.
6 7 8 |
# File 'lib/scopedog/record_class.rb', line 6 def yard_obj @yard_obj end |
Class Method Details
.all(docs: YARD::Registry.all, root_const: Object) ⇒ Array<RecordClass>
11 12 13 14 15 16 17 18 |
# File 'lib/scopedog/record_class.rb', line 11 def self.all(docs: YARD::Registry.all, root_const: Object) docs .select { |d| d.type == :class && d.has_tag?(:record) } .each { |d| require_relative d.file if d.file != '(stdin)' } .map { |d| [d, root_const.const_get(d.path)] } .select { |(_, c)| c.ancestors.include?(ActiveRecord::Base) && !c.abstract_class? } .map { |d, c| RecordClass.new(d, c, root_const: root_const) } end |
Instance Method Details
#default_sql ⇒ String
51 52 53 |
# File 'lib/scopedog/record_class.rb', line 51 def default_sql ar_class.all.to_sql end |
#docstring ⇒ String
34 35 36 |
# File 'lib/scopedog/record_class.rb', line 34 def docstring yard_obj.docstring end |
#name ⇒ String
29 30 31 |
# File 'lib/scopedog/record_class.rb', line 29 def name ar_class.name.gsub(/^#{@root_const.name}::/, '') end |
#scopes ⇒ Array<YARD::CodeObjects::MethodObject>
44 45 46 47 48 |
# File 'lib/scopedog/record_class.rb', line 44 def scopes @scopes ||= yard_obj.meths .select { |m| m.has_tag?(:scoping) } .map { |m| Scope.new(self, m) } end |
#table_name ⇒ String
39 40 41 |
# File 'lib/scopedog/record_class.rb', line 39 def table_name ar_class.table_name end |
#unscoped_sql ⇒ String
56 57 58 |
# File 'lib/scopedog/record_class.rb', line 56 def unscoped_sql ar_class.all.unscoped.to_sql end |