# class Shell::ModelWrapper

### Attributes

model_symbol[R]

### Public Class Methods

new(model_class, symbol=nil) click to toggle source

    # File lib/chef/shell/model_wrapper.rb, line 29
    def initialize(model_class, symbol=nil)
      @model_class = model_class
      @model_symbol = symbol || convert_to_snake_case(model_class.name, "Chef").to_sym
    end

### Public Instance Methods

all(&block) click to toggle source

    # File lib/chef/shell/model_wrapper.rb, line 49
    def all(&block)
      all_objects = list_objects
      block_given? ? all_objects.map(&block) : all_objects
    end

Also aliased as: list
bulk_edit(what_to_transform, &block)
Alias for: transform
find(query)
Alias for: search
list(&block)
Alias for: all
load(obj_id)
Alias for: show
search(query) { |obj| ... } click to toggle source

    # File lib/chef/shell/model_wrapper.rb, line 34
    def search(query)
      return all if query.to_s == "all"
      results = []
      Chef::Search::Query.new.search(@model_symbol, format_query(query)) do |obj|
        if block_given?
          results << yield(obj)
        else
          results << obj
        end
      end
      results
    end

Also aliased as: find
show(obj_id) click to toggle source

    # File lib/chef/shell/model_wrapper.rb, line 56
    def show(obj_id)
      @model_class.load(obj_id)
    end

Also aliased as: load
transform(what_to_transform) { |obj| ... } click to toggle source

    # File lib/chef/shell/model_wrapper.rb, line 62
    def transform(what_to_transform, &block)
      if what_to_transform == :all
        objects_to_transform = list_objects
      else
        objects_to_transform = search(what_to_transform)
      end
      objects_to_transform.each do |obj|
        if result = yield(obj)
          obj.save
        end
      end
    end

Also aliased as: bulk_edit