Class: Scopedog::RecordClass

Inherits:
Object
  • Object
show all
Defined in:
lib/scopedog/record_class.rb

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yard_obj, ar_class, root_const: Object) ⇒ RecordClass

Returns a new instance of RecordClass.

Parameters:

  • yard_obj (YARD::CodeObjects::ClassObject)
  • ar_class (Class<ActiveRecord::Base>)


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_classClass<ActiveRecord::Base> (readonly)

Returns the current value of ar_class.

Returns:

  • (Class<ActiveRecord::Base>)

    the current value of ar_class



6
7
8
# File 'lib/scopedog/record_class.rb', line 6

def ar_class
  @ar_class
end

#yard_objYARD::CodeObjects::ClassObject (readonly)

Returns the current value of yard_obj.

Returns:

  • (YARD::CodeObjects::ClassObject)

    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>

Parameters:

  • docs (Array<YARD::CodeObjects::Base>) (defaults to: YARD::Registry.all)

Returns:



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_sqlString

Returns:

  • (String)


51
52
53
# File 'lib/scopedog/record_class.rb', line 51

def default_sql
  ar_class.all.to_sql
end

#docstringString

Returns:

  • (String)


34
35
36
# File 'lib/scopedog/record_class.rb', line 34

def docstring
  yard_obj.docstring
end

#nameString

Returns:

  • (String)


29
30
31
# File 'lib/scopedog/record_class.rb', line 29

def name
  ar_class.name.gsub(/^#{@root_const.name}::/, '')
end

#scopesArray<YARD::CodeObjects::MethodObject>

Returns:

  • (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_nameString

Returns:

  • (String)


39
40
41
# File 'lib/scopedog/record_class.rb', line 39

def table_name
  ar_class.table_name
end

#unscoped_sqlString

Returns:

  • (String)


56
57
58
# File 'lib/scopedog/record_class.rb', line 56

def unscoped_sql
  ar_class.all.unscoped.to_sql
end