Class: LazyDoc::Commands::ViaCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_doc/commands/via_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ViaCommand

Returns a new instance of ViaCommand.



5
6
7
# File 'lib/lazy_doc/commands/via_command.rb', line 5

def initialize(path)
  @path = [path].flatten
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/lazy_doc/commands/via_command.rb', line 3

def path
  @path
end

Instance Method Details

#execute(document) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/lazy_doc/commands/via_command.rb', line 9

def execute(document)
  path.inject(document) do |final_value, attribute|
    unless final_value.has_key?(attribute.to_s)
      raise LazyDoc::AttributeNotFoundError.new("Unable to access #{attribute} via #{path.join(', ')}")
    end

    final_value[attribute.to_s]
  end
end