Module: Meta::Scope::Base
- Included in:
- Meta::Scope, Composite, Or
- Defined in:
- lib/meta/scope/base.rb
Overview
基本的 Scope 方法,引入该模块即可获取系列方法
Instance Method Summary collapse
-
#and(*scopes) ⇒ Object
(also: #&)
既作为类方法,也作为实例方法.
- #defined_scopes ⇒ Object
- #include_scope(*scopes) ⇒ Object
- #inspect ⇒ Object
- #match?(scopes) ⇒ Boolean
- #match_scopes?(scopes) ⇒ Boolean
-
#or(*scopes) ⇒ Object
(also: #|)
既可以是类方法,也可以是实例方法.
- #scope_name ⇒ Object
- #scope_name=(name) ⇒ Object
Instance Method Details
#and(*scopes) ⇒ Object Also known as: &
既作为类方法,也作为实例方法
41 42 43 44 |
# File 'lib/meta/scope/base.rb', line 41 def and(*scopes) scopes = [self, *scopes] if self != Meta::Scope And.new(*scopes) end |
#defined_scopes ⇒ Object
21 22 23 |
# File 'lib/meta/scope/base.rb', line 21 def defined_scopes [self] end |
#include_scope(*scopes) ⇒ Object
36 37 38 |
# File 'lib/meta/scope/base.rb', line 36 def include_scope(*scopes) @forwarded_scope = Composite.concat(@forwarded_scope, *scopes) end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/meta/scope/base.rb', line 54 def inspect scope_name || super end |
#match?(scopes) ⇒ Boolean
11 12 13 14 |
# File 'lib/meta/scope/base.rb', line 11 def match?(scopes) scopes = [scopes] unless scopes.is_a?(Array) match_scopes?(scopes) end |
#match_scopes?(scopes) ⇒ Boolean
16 17 18 19 |
# File 'lib/meta/scope/base.rb', line 16 def match_scopes?(scopes) return true if @forwarded_scope&.match?(scopes) scopes.include?(self) end |
#or(*scopes) ⇒ Object Also known as: |
既可以是类方法,也可以是实例方法
48 49 50 51 |
# File 'lib/meta/scope/base.rb', line 48 def or(*scopes) scopes = [self, *scopes] if self != Meta::Scope Or.new(*scopes) end |
#scope_name ⇒ Object
25 26 27 28 29 30 |
# File 'lib/meta/scope/base.rb', line 25 def scope_name scope_name = @scope_name || self.name raise Errors::NameNotSet, '未设置 scope 名称' if scope_name.nil? scope_name.split('::').last end |
#scope_name=(name) ⇒ Object
32 33 34 |
# File 'lib/meta/scope/base.rb', line 32 def scope_name=(name) @scope_name = name.to_s end |