Refactoring: Improved folder structure for Mixins.

This commit is contained in:
Thorsten Eckel 2017-09-01 13:59:12 +02:00
parent 702b792eb9
commit 90c1a0faef
4 changed files with 40 additions and 38 deletions

View file

@ -0,0 +1,36 @@
class Sequencer
class Unit
module Common
module Mixin
module DynamicAttribute
def self.included(base)
class << base
def inherited(base)
base.extend(Forwardable)
base.instance_delegate [:attribute] => base
end
def attribute
@attribute ||= begin
if uses.size != 1
raise "DynamicAttribute classes can use exactly one attribute. Found #{uses.size}."
end
uses.first
end
end
end
end
private
def attribute_value
@attribute_value ||= state.use(attribute)
end
end
end
end
end
end

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/mixin/dynamic_attribute'
require 'sequencer/unit/common/mixin/dynamic_attribute'
class Sequencer
class Unit
@ -9,7 +9,7 @@ class Sequencer
module Blank
class Base < Sequencer::Unit::Base
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnProvidedInstanceAction
include ::Sequencer::Unit::Mixin::DynamicAttribute
include ::Sequencer::Unit::Common::Mixin::DynamicAttribute
provides :instance_action

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/mixin/dynamic_attribute'
require 'sequencer/unit/common/mixin/dynamic_attribute'
class Sequencer
class Unit
@ -9,7 +9,7 @@ class Sequencer
module MissingMandatory
class Base < Sequencer::Unit::Base
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::SkipOnProvidedInstanceAction
include ::Sequencer::Unit::Mixin::DynamicAttribute
include ::Sequencer::Unit::Common::Mixin::DynamicAttribute
provides :instance_action

View file

@ -1,34 +0,0 @@
class Sequencer
class Unit
module Mixin
module DynamicAttribute
def self.included(base)
class << base
def inherited(base)
base.extend(Forwardable)
base.instance_delegate [:attribute] => base
end
def attribute
@attribute ||= begin
if uses.size != 1
raise "DynamicAttribute classes can use exactly one attribute. Found #{uses.size}."
end
uses.first
end
end
end
end
private
def attribute_value
@attribute_value ||= state.use(attribute)
end
end
end
end
end