Module: Dockly::Util::DSL
- Defined in:
- lib/dockly/util/dsl.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #==(other_dsl) ⇒ Object
- #[](var) ⇒ Object
- #[]=(var, val) ⇒ Object
- #initialize(options = {}, &block) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
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
142 143 144 |
# File 'lib/dockly/util/dsl.rb', line 142 def ==(other_dsl) (other_dsl.class == self.class) && (other_dsl.name == self.name) end |
#[](var) ⇒ Object
134 135 136 |
# File 'lib/dockly/util/dsl.rb', line 134 def [](var) instance_variable_get(:"@#{var}") end |
#[]=(var, val) ⇒ Object
138 139 140 |
# File 'lib/dockly/util/dsl.rb', line 138 def []=(var, val) instance_variable_set(:"@#{var}", val) end |
#initialize(options = {}, &block) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/dockly/util/dsl.rb', line 145 def initialize( = {}, &block) self.class.default_values.merge().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_hash ⇒ Object
155 156 157 |
# File 'lib/dockly/util/dsl.rb', line 155 def to_hash Hash[instance_variables.map { |ivar| [ivar.to_s[1..-1].to_sym, instance_variable_get(ivar)] }] end |
#to_s ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/dockly/util/dsl.rb', line 126 def to_s "#{self.class.name} (#{ instance_variables.map { |var| "#{var} = #{instance_variable_get(var)}" }.join(', ') })" end |