k_domain 0.0.11 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -1
- data/Gemfile +1 -1
- data/Rakefile +3 -1
- data/STORIES.md +35 -6
- data/k_domain.gemspec +1 -0
- data/lib/k_domain/domain_model/load.rb +8 -2
- data/lib/k_domain/domain_model/transform.rb +24 -49
- data/lib/k_domain/domain_model/transform_steps/_.rb +3 -3
- data/lib/k_domain/domain_model/transform_steps/step.rb +36 -11
- data/lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb +1 -1
- data/lib/k_domain/domain_model/transform_steps/{step8_locate_rails_models.rb → step4_rails_resource_models.rb} +5 -3
- data/lib/k_domain/domain_model/transform_steps/step5_rails_models.rb +71 -0
- data/lib/k_domain/domain_model/transform_steps/{step5_attach_dictionary.rb → step6_attach_dictionary.rb} +9 -3
- data/lib/k_domain/rails_code_extractor/extract_model.rb +58 -0
- data/lib/k_domain/rails_code_extractor/shim_loader.rb +29 -0
- data/lib/k_domain/raw_db_schema/load.rb +8 -2
- data/lib/k_domain/raw_db_schema/transform.rb +5 -6
- data/lib/k_domain/schemas/_.rb +16 -0
- data/lib/k_domain/schemas/database/_.rb +0 -7
- data/lib/k_domain/schemas/database/index.rb +1 -1
- data/lib/k_domain/schemas/database/schema.rb +15 -2
- data/lib/k_domain/schemas/database/table.rb +19 -8
- data/lib/k_domain/schemas/dictionary.rb +19 -0
- data/lib/k_domain/schemas/domain/_.rb +0 -3
- data/lib/k_domain/schemas/domain/domain.rb +1 -2
- data/lib/k_domain/schemas/domain/erd_file.rb +2 -0
- data/lib/k_domain/schemas/domain_model.rb +15 -0
- data/lib/k_domain/schemas/{domain/investigate.rb → investigate.rb} +1 -1
- data/lib/k_domain/schemas/rails_resource.rb +16 -0
- data/lib/k_domain/schemas/rails_structure.rb +92 -0
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +13 -3
- data/templates/active_record_shims.rb +368 -0
- data/templates/fake_module_shims.rb +42 -0
- data/{lib/k_domain/raw_db_schema/template.rb → templates/load_schema.rb} +4 -4
- metadata +16 -12
- data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +0 -454
- data/lib/k_domain/schemas/database/column.rb +0 -16
- data/lib/k_domain/schemas/database/database.rb +0 -11
- data/lib/k_domain/schemas/database/unique_key.rb +0 -14
- data/lib/k_domain/schemas/domain/dictionary.rb +0 -17
- data/lib/k_domain/schemas/domain/schema.rb +0 -13
@@ -3,10 +3,23 @@
|
|
3
3
|
module KDomain
|
4
4
|
module Database
|
5
5
|
class Schema < Dry::Struct
|
6
|
+
class DbInfo < Dry::Struct
|
7
|
+
attribute :type , Types::Strict::String
|
8
|
+
attribute :version , Types::Nominal::Any.optional.default(nil)
|
9
|
+
attribute :extensions , Types::Strict::Array
|
10
|
+
end
|
11
|
+
|
12
|
+
class UniqueKey < Dry::Struct
|
13
|
+
attribute :type , Types::Strict::String
|
14
|
+
attribute :category , Types::Strict::String.optional
|
15
|
+
attribute :key , Types::Strict::String
|
16
|
+
attribute :keys , Types::Strict::Array
|
17
|
+
end
|
18
|
+
|
6
19
|
class Meta < Dry::Struct
|
7
20
|
attribute :rails , Types::Strict::Integer
|
8
|
-
attribute :
|
9
|
-
attribute :unique_keys , Types::Strict::Array.of(KDomain::Database::UniqueKey)
|
21
|
+
attribute :db_info , KDomain::Database::Schema::DbInfo
|
22
|
+
attribute :unique_keys , Types::Strict::Array.of(KDomain::Database::Schema::UniqueKey)
|
10
23
|
end
|
11
24
|
|
12
25
|
attribute :tables , Types::Strict::Array.of(KDomain::Database::Table)
|
@@ -3,19 +3,30 @@
|
|
3
3
|
module KDomain
|
4
4
|
module Database
|
5
5
|
class Table < Dry::Struct
|
6
|
-
class
|
6
|
+
class RailsSchema < Dry::Struct
|
7
7
|
attribute :primary_key , Types::Nominal::Any.optional.default(nil)
|
8
8
|
attribute :id , Types::Nominal::Any.optional.default(nil)
|
9
9
|
attribute :force , Types::Nominal::Any.optional.default(nil)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
class Column < Dry::Struct
|
13
|
+
attribute :name , Types::Strict::String
|
14
|
+
attribute :type , Types::Strict::String
|
15
|
+
attribute :precision? , Types::Strict::Integer.optional.default(nil)
|
16
|
+
attribute :scale? , Types::Strict::Integer.optional.default(nil)
|
17
|
+
attribute :default? , Types::Nominal::Any.optional.default(nil)
|
18
|
+
attribute :array? , Types::Strict::Bool.optional.default(nil)
|
19
|
+
attribute :null? , Types::Strict::Bool.optional.default(nil)
|
20
|
+
attribute :limit? , Types::Strict::Integer.optional.default(nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
attribute :name , Types::Strict::String
|
24
|
+
attribute :primary_key , Types::Strict::String.optional.default(nil)
|
25
|
+
attribute :primary_key_type , Types::Strict::String.optional.default(nil)
|
26
|
+
attribute :id? , Types::Nominal::Any.optional.default(nil)
|
27
|
+
attribute :columns , Types::Strict::Array.of(KDomain::Database::Table::Column)
|
28
|
+
attribute :indexes , Types::Strict::Array.of(KDomain::Database::Index) # May want to have a Table::Index, but for now this is a shared scheam
|
29
|
+
attribute :rails_schema , KDomain::Database::Table::RailsSchema
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain class holds a dictionary entry
|
4
|
+
module KDomain
|
5
|
+
module Schemas
|
6
|
+
class Dictionary < Dry::Struct
|
7
|
+
attribute :items , Types::Strict::Array do
|
8
|
+
attribute :name , Types::Strict::String
|
9
|
+
attribute :type , Types::Strict::String
|
10
|
+
attribute :label , Types::Strict::String
|
11
|
+
attribute :segment , Types::Strict::String
|
12
|
+
attribute :models , Types::Strict::Array
|
13
|
+
attribute :model_count , Types::Strict::Integer
|
14
|
+
attribute :types , Types::Strict::Array
|
15
|
+
attribute :type_count , Types::Strict::Integer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -2,13 +2,10 @@
|
|
2
2
|
|
3
3
|
# log.warn 'models->domain' if AppDebug.require?
|
4
4
|
|
5
|
-
require_relative './dictionary'
|
6
|
-
require_relative './investigate'
|
7
5
|
require_relative './models/column'
|
8
6
|
require_relative './models/model'
|
9
7
|
require_relative './erd_file'
|
10
8
|
require_relative './domain'
|
11
|
-
require_relative './schema'
|
12
9
|
|
13
10
|
module KDomain
|
14
11
|
module DomainModel
|
@@ -5,8 +5,7 @@ module KDomain
|
|
5
5
|
module DomainModel
|
6
6
|
class Domain < Dry::Struct
|
7
7
|
attribute :models , Types::Strict::Array.of(KDomain::DomainModel::Model)
|
8
|
-
attribute :erd_files , Types::Strict::Array.of(KDomain::DomainModel::ErdFile)
|
9
|
-
attribute :dictionary , Types::Strict::Array.of(KDomain::DomainModel::Dictionary)
|
8
|
+
# attribute :erd_files , Types::Strict::Array.of(KDomain::DomainModel::ErdFile)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
# Domain class holds a list of the entities
|
4
4
|
module KDomain
|
5
5
|
module DomainModel
|
6
|
+
# rubocop:disable Metrics/BlockLength
|
6
7
|
class ErdFile < Dry::Struct
|
7
8
|
attribute :name , Types::Strict::String
|
8
9
|
attribute :name_plural , Types::Strict::String
|
@@ -76,5 +77,6 @@ module KDomain
|
|
76
77
|
end
|
77
78
|
end
|
78
79
|
end
|
80
|
+
# rubocop:enable Metrics/BlockLength
|
79
81
|
end
|
80
82
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# DomainModel holds the entire domain model including database and ancillary information
|
4
|
+
module KDomain
|
5
|
+
module Schemas
|
6
|
+
class DomainModel < Dry::Struct
|
7
|
+
attribute :domain , KDomain::DomainModel::Domain
|
8
|
+
attribute :database , KDomain::Database::Schema
|
9
|
+
attribute :dictionary , KDomain::Schemas::Dictionary
|
10
|
+
attribute :rails_resource , KDomain::Schemas::RailsResource
|
11
|
+
attribute :rails_structure , KDomain::Schemas::RailsStructure
|
12
|
+
attribute :investigate , KDomain::Schemas::Investigate
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain class holds a dictionary entry
|
4
|
+
module KDomain
|
5
|
+
module Schemas
|
6
|
+
class RailsResource < Dry::Struct
|
7
|
+
attribute :models , Types::Strict::Array do
|
8
|
+
attribute :model_name , Types::Strict::String
|
9
|
+
attribute :table_name , Types::Strict::String
|
10
|
+
attribute :file , Types::Strict::String
|
11
|
+
attribute :exist , Types::Strict::Bool
|
12
|
+
attribute :state , Types::Strict::String
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain class holds a dictionary entry
|
4
|
+
module KDomain
|
5
|
+
module Schemas
|
6
|
+
class RailsStructure < Dry::Struct
|
7
|
+
class DefaultScope < Dry::Struct
|
8
|
+
attribute :block? , Types::Strict::String
|
9
|
+
end
|
10
|
+
|
11
|
+
class BaseType < Dry::Struct
|
12
|
+
attribute :name? , Types::Strict::String
|
13
|
+
attribute :opts? , Types::Strict::Hash
|
14
|
+
attribute :block? , Types::Strict::String.optional.default(nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Scope < KDomain::Schemas::RailsStructure::BaseType
|
18
|
+
end
|
19
|
+
|
20
|
+
class BelongsTo < KDomain::Schemas::RailsStructure::BaseType
|
21
|
+
end
|
22
|
+
|
23
|
+
class HasOne < KDomain::Schemas::RailsStructure::BaseType
|
24
|
+
end
|
25
|
+
|
26
|
+
class HasMany < KDomain::Schemas::RailsStructure::BaseType
|
27
|
+
end
|
28
|
+
|
29
|
+
class HasAndBelongsToMany < KDomain::Schemas::RailsStructure::BaseType
|
30
|
+
end
|
31
|
+
|
32
|
+
class Validate < Dry::Struct
|
33
|
+
attribute :names? , Types::Array.of(Types::Strict::String)
|
34
|
+
attribute :opts? , Types::Strict::Hash
|
35
|
+
attribute :block? , Types::Strict::String.optional.default(nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
class Validates < KDomain::Schemas::RailsStructure::BaseType
|
39
|
+
end
|
40
|
+
|
41
|
+
class Behaviours < Dry::Struct
|
42
|
+
attribute :class_name? , Types::Strict::String
|
43
|
+
attribute :default_scope? , KDomain::Schemas::RailsStructure::DefaultScope
|
44
|
+
attribute :scopes? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Scope)
|
45
|
+
attribute :belongs_to? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::BelongsTo)
|
46
|
+
attribute :has_one? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::HasOne)
|
47
|
+
attribute :has_many? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::HasMany)
|
48
|
+
attribute :has_and_belongs_to_many? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::HasAndBelongsToMany)
|
49
|
+
attribute :validate? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Validate)
|
50
|
+
attribute :validates? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Validates)
|
51
|
+
attribute :attr_accessor? , Types::Array.of(Types::Strict::String)
|
52
|
+
attribute :attr_reader? , Types::Array.of(Types::Strict::String)
|
53
|
+
attribute :attr_writer? , Types::Array.of(Types::Strict::String)
|
54
|
+
end
|
55
|
+
|
56
|
+
class Method < Dry::Struct
|
57
|
+
attribute :name , Types::Strict::String
|
58
|
+
end
|
59
|
+
|
60
|
+
class Functions < Dry::Struct
|
61
|
+
attribute :class_name? , Types::Strict::String
|
62
|
+
attribute :module_name? , Types::Strict::String
|
63
|
+
attribute :class_full_name? , Types::Strict::String
|
64
|
+
attribute :attr_accessor? , Types::Array.of(Types::Strict::String)
|
65
|
+
attribute :attr_reader? , Types::Array.of(Types::Strict::String)
|
66
|
+
attribute :attr_writer? , Types::Array.of(Types::Strict::String)
|
67
|
+
attribute :klass? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Method)
|
68
|
+
attribute :instance_public? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Method)
|
69
|
+
attribute :instance_private? , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Method)
|
70
|
+
end
|
71
|
+
|
72
|
+
class Model < Dry::Struct
|
73
|
+
attribute :model_name , Types::Strict::String
|
74
|
+
attribute :table_name , Types::Strict::String
|
75
|
+
attribute :file , Types::Strict::String
|
76
|
+
attribute :exist , Types::Strict::Bool
|
77
|
+
attribute :state , Types::Strict::String
|
78
|
+
attribute :code , Types::Strict::String
|
79
|
+
attribute :behaviours? , KDomain::Schemas::RailsStructure::Behaviours
|
80
|
+
attribute :functions? , KDomain::Schemas::RailsStructure::Functions
|
81
|
+
end
|
82
|
+
|
83
|
+
class Controller < Dry::Struct
|
84
|
+
end
|
85
|
+
|
86
|
+
attribute :models , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Model)
|
87
|
+
attribute :controllers , Types::Strict::Array.of(KDomain::Schemas::RailsStructure::Controller)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# attribute :domain , KDomain::DomainModel::Domain
|
data/lib/k_domain/version.rb
CHANGED
data/lib/k_domain.rb
CHANGED
@@ -5,14 +5,14 @@ require 'dry-struct'
|
|
5
5
|
require 'k_log'
|
6
6
|
require 'peeky'
|
7
7
|
require 'k_domain/version'
|
8
|
-
require 'k_domain/schemas/
|
9
|
-
require 'k_domain/schemas/domain/_'
|
10
|
-
|
8
|
+
require 'k_domain/schemas/_'
|
11
9
|
require 'k_domain/raw_db_schema/transform'
|
12
10
|
require 'k_domain/raw_db_schema/load'
|
13
11
|
require 'k_domain/domain_model/transform'
|
14
12
|
require 'k_domain/domain_model/transform_steps/_'
|
15
13
|
require 'k_domain/domain_model/load'
|
14
|
+
require 'k_domain/rails_code_extractor/shim_loader'
|
15
|
+
require 'k_domain/rails_code_extractor/extract_model'
|
16
16
|
|
17
17
|
# # This is useful if you want to initialize structures via Hash
|
18
18
|
# class SymbolizeStruct < Dry::Struct
|
@@ -23,6 +23,16 @@ module KDomain
|
|
23
23
|
# raise KDomain::Error, 'Sample message'
|
24
24
|
class Error < StandardError; end
|
25
25
|
|
26
|
+
module Gem
|
27
|
+
def self.root
|
28
|
+
File.expand_path('..', File.dirname(__FILE__))
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.resource(resource_path)
|
32
|
+
File.join(root, resource_path)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
26
36
|
# Your code goes here...
|
27
37
|
end
|
28
38
|
|
@@ -0,0 +1,368 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
def self.current_class
|
3
|
+
@current_class ||= nil
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.current_class=(value)
|
7
|
+
@current_class = value
|
8
|
+
end
|
9
|
+
|
10
|
+
class Base
|
11
|
+
def self.singleton_class
|
12
|
+
Class.new do
|
13
|
+
def send(*_p, **_o); end
|
14
|
+
end.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.class_info
|
18
|
+
return ActiveRecord.current_class if ActiveRecord.current_class
|
19
|
+
|
20
|
+
ActiveRecord.current_class = {
|
21
|
+
class_name: name
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.set(key, value)
|
26
|
+
class_info[key] = class_info[key] || {}
|
27
|
+
class_info[key] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.add(key, value)
|
31
|
+
class_info[key] = class_info[key] || []
|
32
|
+
if value.is_a?(Array)
|
33
|
+
class_info[key] = class_info[key] + value
|
34
|
+
else
|
35
|
+
class_info[key] << value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.custom_set(key, value = {})
|
40
|
+
class_info[:custom] = {} unless class_info[:custom]
|
41
|
+
class_info[:custom][key] = class_info[:custom][key] || {}
|
42
|
+
class_info[:custom][key] = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.custom_add(key, value)
|
46
|
+
class_info[:custom] = {} unless class_info[:custom]
|
47
|
+
class_info[:custom][key] = class_info[:custom][key] || []
|
48
|
+
if value.is_a?(Array)
|
49
|
+
class_info[:custom][key] = class_info[:custom][key] + value
|
50
|
+
else
|
51
|
+
class_info[:custom][key] << value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# examples:
|
56
|
+
# enum status: { active: 0, archived: 1 }
|
57
|
+
# enum status: [:active, :archived]
|
58
|
+
# enum status: [:active, :archived], _suffix: true
|
59
|
+
# enum comments_status: [:active, :inactive], _prefix: :comments
|
60
|
+
def self.enum(**opts)
|
61
|
+
add(:enum, opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
# def self.attr_accessor(*args)
|
65
|
+
# args.each do |arg|
|
66
|
+
# self.class_eval("def #{arg};@#{arg};end")
|
67
|
+
# self.class_eval("def #{arg}=(val);@#{arg}=val;end")
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
# def self.attr_reader(*args)
|
71
|
+
# args.each do |arg|
|
72
|
+
# self.class_eval("def #{arg};@#{arg};end")
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
# def self.attr_writer(*args)
|
76
|
+
# args.each do |arg|
|
77
|
+
# self.class_eval("def #{arg};@#{arg};end")
|
78
|
+
# self.class_eval("def #{arg}=(val);@#{arg}=val;end")
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
|
82
|
+
def self.attr_accessor(*names)
|
83
|
+
super(*names)
|
84
|
+
add(:attr_accessor, names)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.attr_reader(*names)
|
88
|
+
super(*names)
|
89
|
+
add(:attr_reader, names)
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.attr_writer(*names)
|
93
|
+
super(*names)
|
94
|
+
add(:attr_writer, names)
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.lambda_source(a_lambda, prefix = nil)
|
98
|
+
return nil unless a_lambda
|
99
|
+
|
100
|
+
puts 'NOT A LAMBDA' unless a_lambda.is_a?(Proc)
|
101
|
+
|
102
|
+
result = a_lambda&.source&.strip
|
103
|
+
result = result&.delete_prefix(prefix) if prefix
|
104
|
+
result&.strip
|
105
|
+
end
|
106
|
+
|
107
|
+
# examples
|
108
|
+
# default_scope where(:published => true) # NOT supported
|
109
|
+
# default_scope { where(:published_at => Time.now - 1.week) }
|
110
|
+
# default_scope -> { order(:external_updated_at) }
|
111
|
+
# default_scope -> { where(:published => true) }, all_queries: true
|
112
|
+
def self.default_scope(**opts, &block)
|
113
|
+
block_source = nil
|
114
|
+
block_source = lambda_source(block, 'default_scope') if block_given?
|
115
|
+
|
116
|
+
set(:default_scope, opts.merge(block: block_source))
|
117
|
+
end
|
118
|
+
|
119
|
+
# examples
|
120
|
+
# scope :red, where(:color => 'red') # NOT SUPPORTED
|
121
|
+
# scope :dry_clean_only, joins(:washing_instructions).where('washing_instructions.dry_clean_only = ?', true) # NOT SUPPORTED
|
122
|
+
#
|
123
|
+
def self.scope(name, on_the_lamb = nil, **opts)
|
124
|
+
lamb_source = lambda_source(on_the_lamb, "scope :#{name},")
|
125
|
+
|
126
|
+
add(:scopes, {
|
127
|
+
name: name,
|
128
|
+
opts: opts,
|
129
|
+
block: lamb_source
|
130
|
+
})
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.belongs_to(name, on_the_lamb = nil, **opts)
|
134
|
+
lamb_source = lambda_source(on_the_lamb, "belongs_to :#{name},")
|
135
|
+
|
136
|
+
add(:belongs_to, {
|
137
|
+
name: name,
|
138
|
+
opts: opts,
|
139
|
+
block: lamb_source
|
140
|
+
})
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.has_many(name, on_the_lamb = nil, **opts)
|
144
|
+
lamb_source = lambda_source(on_the_lamb, "has_many :#{name},")
|
145
|
+
|
146
|
+
add(:has_many, {
|
147
|
+
name: name,
|
148
|
+
opts: opts,
|
149
|
+
block: lamb_source
|
150
|
+
})
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.has_one(name, on_the_lamb = nil, **opts)
|
154
|
+
lamb_source = lambda_source(on_the_lamb, "has_one :#{name},")
|
155
|
+
|
156
|
+
add(:has_one, {
|
157
|
+
name: name,
|
158
|
+
opts: opts,
|
159
|
+
block: lamb_source
|
160
|
+
})
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.has_and_belongs_to_many(name, on_the_lamb = nil, **opts)
|
164
|
+
lamb_source = lambda_source(on_the_lamb, "has_and_belongs_to_many :#{name},")
|
165
|
+
|
166
|
+
add(:has_and_belongs_to_many, {
|
167
|
+
name: name,
|
168
|
+
opts: opts,
|
169
|
+
block: lamb_source
|
170
|
+
})
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.validate(*names, **opts, &block)
|
174
|
+
block_source = nil
|
175
|
+
block_source = lambda_source(block, 'validate') if block_given?
|
176
|
+
|
177
|
+
add(:validate, {
|
178
|
+
names: names,
|
179
|
+
opts: opts,
|
180
|
+
block: block_source
|
181
|
+
})
|
182
|
+
end
|
183
|
+
|
184
|
+
def self.validates(name, **opts)
|
185
|
+
add(:validates, {
|
186
|
+
name: name,
|
187
|
+
opts: opts
|
188
|
+
})
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.alias_attribute(left, right)
|
192
|
+
add(:alias_attribute, {
|
193
|
+
left: left,
|
194
|
+
right: right
|
195
|
+
})
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.before_create(name)
|
199
|
+
add(:before_create, {
|
200
|
+
name: name
|
201
|
+
})
|
202
|
+
end
|
203
|
+
|
204
|
+
def self.before_save(name)
|
205
|
+
add(:before_save, {
|
206
|
+
name: name
|
207
|
+
})
|
208
|
+
end
|
209
|
+
|
210
|
+
def self.before_destroy(name)
|
211
|
+
add(:before_destroy, {
|
212
|
+
name: name
|
213
|
+
})
|
214
|
+
end
|
215
|
+
|
216
|
+
def self.before_validation(name = nil, &block)
|
217
|
+
block_source = nil
|
218
|
+
block_source = lambda_source(block, 'before_validation') if block_given?
|
219
|
+
|
220
|
+
add(:before_validation, {
|
221
|
+
name: name,
|
222
|
+
block: block_source
|
223
|
+
})
|
224
|
+
end
|
225
|
+
|
226
|
+
def self.after_create(name)
|
227
|
+
add(:after_create, {
|
228
|
+
name: name
|
229
|
+
})
|
230
|
+
end
|
231
|
+
|
232
|
+
def self.after_save(name)
|
233
|
+
add(:after_save, {
|
234
|
+
name: name
|
235
|
+
})
|
236
|
+
end
|
237
|
+
|
238
|
+
def self.after_destroy(name = nil, &block)
|
239
|
+
block_source = nil
|
240
|
+
block_source = lambda_source(block, 'after_destroy') if block_given?
|
241
|
+
|
242
|
+
add(:after_destroy, {
|
243
|
+
name: name,
|
244
|
+
block: block_source
|
245
|
+
})
|
246
|
+
end
|
247
|
+
|
248
|
+
def self.after_commit(name)
|
249
|
+
add(:after_commit, {
|
250
|
+
name: name
|
251
|
+
})
|
252
|
+
end
|
253
|
+
|
254
|
+
def self.accepts_nested_attributes_for(name, **opts)
|
255
|
+
add(:accepts_nested_attributes_for, {
|
256
|
+
name: name,
|
257
|
+
opts: opts
|
258
|
+
})
|
259
|
+
end
|
260
|
+
|
261
|
+
def self.has_secure_token(name)
|
262
|
+
add(:has_secure_token, {
|
263
|
+
name: name
|
264
|
+
})
|
265
|
+
end
|
266
|
+
|
267
|
+
# CAN THESE BE AUTOMATED LIKE INCLUDE MODULES
|
268
|
+
def self.establish_connection(connection)
|
269
|
+
class_info[:establish_connection] = connection
|
270
|
+
end
|
271
|
+
|
272
|
+
def self.store_accessor(*names)
|
273
|
+
class_info[:store_accessor] = *names
|
274
|
+
end
|
275
|
+
|
276
|
+
def self.table_name=(table_name)
|
277
|
+
class_info[:table_name] = table_name
|
278
|
+
end
|
279
|
+
|
280
|
+
def self.primary_key=(primary_key)
|
281
|
+
class_info[:primary_key] = primary_key
|
282
|
+
end
|
283
|
+
|
284
|
+
def self.require(require)
|
285
|
+
add(:require, require)
|
286
|
+
end
|
287
|
+
|
288
|
+
def self.devise(*names)
|
289
|
+
add(:devise, names)
|
290
|
+
end
|
291
|
+
|
292
|
+
def self.pg_search_scope(name, **opts)
|
293
|
+
custom_set(:pg_search_scope, {
|
294
|
+
name: name,
|
295
|
+
opts: opts
|
296
|
+
})
|
297
|
+
end
|
298
|
+
|
299
|
+
def self.acts_as_readable(**opts)
|
300
|
+
custom_set(:acts_as_readable, {
|
301
|
+
opts: opts
|
302
|
+
})
|
303
|
+
end
|
304
|
+
|
305
|
+
def self.acts_as_reader
|
306
|
+
custom_set(:acts_as_reader, {})
|
307
|
+
end
|
308
|
+
|
309
|
+
def self.acts_as_commentable
|
310
|
+
custom_set(:acts_as_commentable, {})
|
311
|
+
end
|
312
|
+
|
313
|
+
def self.acts_as_list(**opts)
|
314
|
+
custom_set(:acts_as_list, {
|
315
|
+
opts: opts
|
316
|
+
})
|
317
|
+
end
|
318
|
+
|
319
|
+
def self.has_paper_trail
|
320
|
+
custom_set(:has_paper_trail)
|
321
|
+
end
|
322
|
+
|
323
|
+
def self.validates_uniqueness_of(name, **opts)
|
324
|
+
custom_set(:validates_uniqueness_of, {
|
325
|
+
name: name,
|
326
|
+
opts: opts
|
327
|
+
})
|
328
|
+
end
|
329
|
+
|
330
|
+
def self.validates_presence_of(name, **opts)
|
331
|
+
custom_set(:validates_presence_of, {
|
332
|
+
name: name,
|
333
|
+
opts: opts
|
334
|
+
})
|
335
|
+
end
|
336
|
+
|
337
|
+
def self.validates_length_of(name, **opts)
|
338
|
+
custom_set(:validates_length_of, {
|
339
|
+
name: name,
|
340
|
+
opts: opts
|
341
|
+
})
|
342
|
+
end
|
343
|
+
|
344
|
+
def self.attr_encrypted(name, **opts)
|
345
|
+
custom_set(:attr_encrypted, {
|
346
|
+
name: name,
|
347
|
+
opts: opts
|
348
|
+
})
|
349
|
+
end
|
350
|
+
|
351
|
+
def self.validates_confirmation_of(name, **opts)
|
352
|
+
custom_set(:validates_confirmation_of, {
|
353
|
+
name: name,
|
354
|
+
opts: opts
|
355
|
+
})
|
356
|
+
end
|
357
|
+
|
358
|
+
def self.with_options(opts, &block)
|
359
|
+
block_source = nil
|
360
|
+
block_source = lambda_source(block) if block_given?
|
361
|
+
|
362
|
+
custom_add(:with_options, {
|
363
|
+
opts: opts,
|
364
|
+
block: block_source
|
365
|
+
})
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|