Module: CodeBox::ActsAsCode

Defined in:
lib/code-box/acts_as_code.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.[](*options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/code-box/acts_as_code.rb', line 9

def self.[](*options)
  @opts = options.dup

  instance_eval <<-RUBY_
    class << self
      def _code_box_i18n_model_segment
        "#{options.extract_options![:i18n_model_segment]}"
      end
    end
  RUBY_

  self
end

.included(base) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/code-box/acts_as_code.rb', line 23

def self.included(base)
  unless (class << self; self; end).method_defined?(:_code_box_i18n_model_segment)
    instance_eval <<-RUBY_
      class << self
        def _code_box_i18n_model_segment
          nil
        end
      end
    RUBY_
  end

  instance_eval <<-RUBY_
    class << base
      def _code_box_i18n_model_segment
        return CodeBox.i18n_model_segment if "#{self._code_box_i18n_model_segment}".empty?
        "#{self._code_box_i18n_model_segment}"
      end
    end
  RUBY_

  base.extend(ClassMethods)
  base.acts_as_code(*@opts) if @opts
end