Module: BuilderSupport

Defined in:
lib/builder_support.rb,
lib/builder_support/version.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/builder_support.rb', line 4

def self.included(base)
  base.class_eval do
    def self.builder_support rmv: [ ], add: [ ]
      extend ClassMethods
      delegate :show_attrs, :flatten_attrs, to: self
      include InstanceMethods

      builder_rmv *rmv
      # %i[ a, b, c d ]
      # %i[ flatten: a b, other_declare: c d ]
      # 'a b and c'
      # 'flatten: a and b, other_declare: c and d'
      add = add.split(/ and | /) if add.is_a? String
      add.map { |item| item[','] ? [item.to_s.delete(','), ','] : item }
          .flatten.map(&:to_sym).split(:',').each do |attrs|
        builder_add *attrs
      end
    end
  end
end