Class: Shirinji::Scope
- Inherits:
-
Object
- Object
- Shirinji::Scope
- Defined in:
- lib/shirinji/scope.rb
Constant Summary collapse
- VALID_OPTIONS =
%i[ module prefix suffix klass_suffix auto_klass auto_prefix construct ].freeze
Instance Attribute Summary collapse
-
#auto_klass ⇒ Object
readonly
Returns the value of attribute auto_klass.
-
#auto_prefix ⇒ Object
readonly
Returns the value of attribute auto_prefix.
-
#construct ⇒ Object
readonly
Returns the value of attribute construct.
-
#klass_suffix ⇒ Object
readonly
Returns the value of attribute klass_suffix.
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
Instance Method Summary collapse
- #bean(name, klass: nil, **options, &block) ⇒ Object
-
#initialize(parent, **options, &block) ⇒ Scope
constructor
A new instance of Scope.
- #scope(**options, &block) ⇒ Object
Constructor Details
#initialize(parent, **options, &block) ⇒ Scope
Returns a new instance of Scope.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/shirinji/scope.rb', line 12 def initialize(parent, **, &block) () @parent = parent @mod = [:module] @suffix = [:suffix] @klass_suffix = [:klass_suffix] @auto_klass = [:auto_klass] @auto_prefix = [:auto_prefix] @prefix = generate_prefix([:prefix]) @construct = .fetch(:construct, true) instance_eval(&block) if block end |
Instance Attribute Details
#auto_klass ⇒ Object (readonly)
Returns the value of attribute auto_klass.
9 10 11 |
# File 'lib/shirinji/scope.rb', line 9 def auto_klass @auto_klass end |
#auto_prefix ⇒ Object (readonly)
Returns the value of attribute auto_prefix.
9 10 11 |
# File 'lib/shirinji/scope.rb', line 9 def auto_prefix @auto_prefix end |
#construct ⇒ Object (readonly)
Returns the value of attribute construct.
9 10 11 |
# File 'lib/shirinji/scope.rb', line 9 def construct @construct end |
#klass_suffix ⇒ Object (readonly)
Returns the value of attribute klass_suffix.
9 10 11 |
# File 'lib/shirinji/scope.rb', line 9 def klass_suffix @klass_suffix end |
#mod ⇒ Object (readonly)
Returns the value of attribute mod.
9 10 11 |
# File 'lib/shirinji/scope.rb', line 9 def mod @mod end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
9 10 11 |
# File 'lib/shirinji/scope.rb', line 9 def parent @parent end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/shirinji/scope.rb', line 9 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
9 10 11 |
# File 'lib/shirinji/scope.rb', line 9 def suffix @suffix end |
Instance Method Details
#bean(name, klass: nil, **options, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/shirinji/scope.rb', line 27 def bean(name, klass: nil, **, &block) default_opts = compact({ construct: construct }) klass = generate_klass(name, klass) unless [:value] = compact(default_opts.merge().merge(klass: klass)) scoped_name = generate_scope(name) parent.bean(scoped_name, **, &block) end |