Module: Dockly::Util::DSL

Defined in:
lib/dockly/util/dsl.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
7
# File 'lib/dockly/util/dsl.rb', line 2

def self.included(base)
  base.instance_eval do
    extend ClassMethods
    dsl_attribute :name
  end
end

Instance Method Details

#==(other_dsl) ⇒ Object



92
93
94
# File 'lib/dockly/util/dsl.rb', line 92

def ==(other_dsl)
  (other_dsl.class == self.class) && (other_dsl.name == self.name)
end

#[](var) ⇒ Object



84
85
86
# File 'lib/dockly/util/dsl.rb', line 84

def [](var)
  instance_variable_get(:"@#{var}")
end

#[]=(var, val) ⇒ Object



88
89
90
# File 'lib/dockly/util/dsl.rb', line 88

def []=(var, val)
  instance_variable_set(:"@#{var}", val)
end

#initialize(options = {}, &block) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/dockly/util/dsl.rb', line 95

def initialize(options = {}, &block)
  self.class.default_values.merge(options).each do |k, v|
    v = v.dup rescue v unless v.class.ancestors.include?(Dockly::Util::DSL)
    public_send(k, v)
  end
  instance_eval(&block) unless block.nil?
  name(self.class.generate_unique_name) if name.nil?
  self.instance_variable_get(:@name).freeze
end

#to_hashObject



105
106
107
# File 'lib/dockly/util/dsl.rb', line 105

def to_hash
  Hash[instance_variables.map { |ivar| [ivar.to_s[1..-1].to_sym, instance_variable_get(ivar)] }]
end

#to_sObject



76
77
78
79
80
81
82
# File 'lib/dockly/util/dsl.rb', line 76

def to_s
  "#{self.class.name} (#{
    instance_variables.map { |var|
      "#{var} = #{instance_variable_get(var)}"
    }.join(', ')
  })"
end