module RubyFeatures::Concern::Feature

Private Class Methods

extended(base) click to toggle source
# File lib/ruby-features/concern/feature.rb, line 33
def self.extended(base)
  base.instance_variable_set(:@_dependencies, [])
  base.instance_variable_set(:@_conditions, RubyFeatures::Conditions.new)
  base.instance_variable_set(:@_apply_to_definitions, {})
  base.instance_variable_set(:@_applied, false)
end

Public Instance Methods

_set_feature_name(name) click to toggle source
# File lib/ruby-features/concern/feature.rb, line 23
def _set_feature_name(name)
  @_feature_name = name
end
applied?() click to toggle source
# File lib/ruby-features/concern/feature.rb, line 19
def applied?
  @_applied
end
apply() click to toggle source
# File lib/ruby-features/concern/feature.rb, line 5
def apply
  unless applied?
    RubyFeatures.apply(*@_dependencies)

    @_apply_to_definitions.keys.each do |target|
      RubyFeatures::Lazy.apply(target) do
        _lazy_apply(target)
      end
    end

    @_applied = true
  end
end
feature_name() click to toggle source
# File lib/ruby-features/concern/feature.rb, line 27
def feature_name
  @_feature_name
end

Private Instance Methods

_lazy_apply(target) click to toggle source
# File lib/ruby-features/concern/feature.rb, line 55
def _lazy_apply(target)
  apply_to_module = RubyFeatures::Utils.prepare_module!(self, target)
  apply_to_module.extend RubyFeatures::Concern::ApplyTo
  apply_to_module._apply(target, @_apply_to_definitions.delete(target), @_conditions)
rescue NameError => e
  raise ApplyError.new("[#{feature_name}] #{e.message}")
end
apply_to(target, asserts = {}, &block) click to toggle source
# File lib/ruby-features/concern/feature.rb, line 49
def apply_to(target, asserts = {}, &block)
  target = target.to_s

  (@_apply_to_definitions[target] ||= []) << { asserts: asserts, block: block }
end
condition(condition_name, &block) click to toggle source
# File lib/ruby-features/concern/feature.rb, line 45
def condition(condition_name, &block)
  @_conditions.push(condition_name, block)
end
dependencies(*feature_names) click to toggle source
# File lib/ruby-features/concern/feature.rb, line 40
def dependencies(*feature_names)
  @_dependencies.push(*feature_names).uniq!
end
Also aliased as: dependency
dependency(*feature_names)
Alias for: dependencies