Skip to content

Commit

Permalink
Change Itamae::Resource::Base reciveing options at initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
ganmacs committed Jul 13, 2015
1 parent 1b9aa72 commit cf7f563
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
14 changes: 8 additions & 6 deletions lib/itamae/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ def find_recipe_in_gem(recipe)
end
end

def initialize(runner, path)
def initialize(runner, path, options = {})
@runner = runner
@path = path
@delayed_notifications = []
@children = RecipeChildren.new
@options = options
end

def dir
::File.dirname(@path)
end

def load(vars = {})
context = EvalContext.new(self, vars)
context = EvalContext.new(self, vars, @options)
context.instance_eval(File.read(path), path, 1)
end

Expand Down Expand Up @@ -67,8 +68,9 @@ def show_banner
end

class EvalContext
def initialize(recipe, vars)
def initialize(recipe, vars, options = {})
@recipe = recipe
@options = options

vars.each do |k, v|
define_singleton_method(k) { v }
Expand All @@ -92,7 +94,7 @@ def method_missing(*args, &block)
super
end

resource = klass.new(@recipe, name, &block)
resource = klass.new(@recipe, name, @options, &block)
@recipe.children << resource
end

Expand All @@ -116,7 +118,7 @@ def include_recipe(target)
return
end

recipe = Recipe.new(runner, path)
recipe = Recipe.new(runner, path, @options)
@recipe.children << recipe
recipe.load
end
Expand All @@ -138,7 +140,7 @@ class RecipeFromDefinition < Recipe
attr_accessor :definition

def load(vars = {})
context = EvalContext.new(self, vars)
context = EvalContext.new(self, vars, @options)
context.instance_eval(&@definition.class.definition_block)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/itamae/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ def define_attribute(name, options)
attr_reader :notifications
attr_reader :updated

def initialize(recipe, resource_name, &block)
def initialize(recipe, resource_name, options = {}, &block)
clear_current_attributes
@recipe = recipe
@resource_name = resource_name
@options = options
@updated = false

EvalContext.new(self).tap do |context|
Expand Down Expand Up @@ -360,4 +361,3 @@ def verify
end
end
end

9 changes: 5 additions & 4 deletions lib/itamae/resource/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ def pre_action
when :edit
attributes.exist = true

content = backend.receive_file(attributes.path)
attributes.block.call(content)
attributes.content = content
unless @options[:dry_run]
content = backend.receive_file(attributes.path)
attributes.block.call(content)
attributes.content = content
end
end

send_tempfile
Expand Down Expand Up @@ -145,4 +147,3 @@ def send_tempfile
end
end
end

3 changes: 1 addition & 2 deletions lib/itamae/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def initialize(backend, options)

def load_recipes(paths)
paths.each do |path|
recipe = Recipe.new(self, File.expand_path(path))
recipe = Recipe.new(self, File.expand_path(path), @options)
children << recipe
recipe.load
end
Expand Down Expand Up @@ -85,4 +85,3 @@ def create_node
end
end
end

0 comments on commit cf7f563

Please sign in to comment.