Class: Maglev::KnowledgeConfig::Builder
- Inherits:
-
Object
- Object
- Maglev::KnowledgeConfig::Builder
- Defined in:
- lib/maglev/knowledge_config.rb
Instance Method Summary collapse
- #build(&block) ⇒ Object
- #expose(*attributes) ⇒ Object
- #expose_attached(*names) ⇒ Object
- #expose_rich_text(*names) ⇒ Object
- #hide(*attributes) ⇒ Object
- #include_related(association, depth:, limit:, inverse: nil) ⇒ Object
-
#initialize(model_class) ⇒ Builder
constructor
A new instance of Builder.
- #tags(*tags) ⇒ Object
Constructor Details
#initialize(model_class) ⇒ Builder
Returns a new instance of Builder.
63 64 65 66 67 68 69 70 71 |
# File 'lib/maglev/knowledge_config.rb', line 63 def initialize(model_class) @model_class = model_class @exposed_attributes = [] @hidden_attributes = [] @tags = [] @relations = [] @attached_sources = [] @rich_text_sources = [] end |
Instance Method Details
#build(&block) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/maglev/knowledge_config.rb', line 73 def build(&block) instance_eval(&block) if block validate! KnowledgeConfig.new( model_class: @model_class, exposed_attributes: normalize(@exposed_attributes), hidden_attributes: normalize(@hidden_attributes), tags: normalize(@tags), relations: @relations.uniq { |relation| relation.name }, attached_sources: @attached_sources.uniq(&:name), rich_text_sources: @rich_text_sources.uniq(&:name) ) end |
#expose(*attributes) ⇒ Object
88 89 90 |
# File 'lib/maglev/knowledge_config.rb', line 88 def expose(*attributes) @exposed_attributes.concat(attributes) end |
#expose_attached(*names) ⇒ Object
104 105 106 |
# File 'lib/maglev/knowledge_config.rb', line 104 def expose_attached(*names) @attached_sources.concat(names.map { |name| ContentSource.new(name) }) end |
#expose_rich_text(*names) ⇒ Object
108 109 110 |
# File 'lib/maglev/knowledge_config.rb', line 108 def expose_rich_text(*names) @rich_text_sources.concat(names.map { |name| ContentSource.new(name) }) end |
#hide(*attributes) ⇒ Object
92 93 94 |
# File 'lib/maglev/knowledge_config.rb', line 92 def hide(*attributes) @hidden_attributes.concat(attributes) end |
#include_related(association, depth:, limit:, inverse: nil) ⇒ Object
100 101 102 |
# File 'lib/maglev/knowledge_config.rb', line 100 def (association, depth:, limit:, inverse: nil) @relations << Relation.new(name: association, depth: depth, limit: limit, inverse: inverse) end |
#tags(*tags) ⇒ Object
96 97 98 |
# File 'lib/maglev/knowledge_config.rb', line 96 def (*) @tags.concat() end |