Class: Architecture::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/architecture/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(source:, destination:, output: STDOUT, level: 0) {|_self| ... } ⇒ DSL

Returns a new instance of DSL.

Yields:

  • (_self)

Yield Parameters:



5
6
7
8
9
10
11
12
# File 'lib/architecture/dsl.rb', line 5

def initialize(source:, destination:, output: STDOUT, level: 0)
  @source = source
  @destination = destination
  @output = output
  @level = level

  yield(self)
end

Instance Method Details

#append(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/architecture/dsl.rb', line 89

def append(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil)
  a = Entity.new(id: directory || file, prefix: location || @destination)

  @output.print("#{indentention}Appending #{a}")

  Append.new(source: a, content: content, context: context).call

  @output.puts(" succeeded.")
end

#copy(file: nil, directory: nil, as: nil, context: EMPTY_CONTEXT, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/architecture/dsl.rb', line 14

def copy(file: nil, directory: nil, as: nil, context: EMPTY_CONTEXT, &block)
  a = Entity.new(id: directory || file, prefix: @source)
  b = Entity.new(id: as || directory || file, prefix: @destination)

  @output.print("#{indentention}Copying #{a} to #{b}")

  Copy.new(source: a, destination: b, context: context).call

  @output.puts(" succeeded.")

  if block_given? && directory
    within(directory: directory, &block)
  end
end

#create(file: nil, directory: nil, content: nil, context: EMPTY_CONTEXT, location: nil, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/architecture/dsl.rb', line 44

def create(file: nil, directory: nil, content: nil, context: EMPTY_CONTEXT, location: nil, &block)
  a = Entity.new(id: directory || file, prefix: location || @destination)

  @output.print("#{indentention}Creating #{a}")

  Create.new(source: a, content: content, context: context).call

  @output.puts(" succeeded.")

  if block_given? && directory
    within(directory: directory, &block)
  end
end

#delete(directory: nil, file: nil, location: nil) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/architecture/dsl.rb', line 58

def delete(directory: nil, file: nil, location: nil)
  a = Entity.new(id: directory || file, prefix: location || @destination)

  @output.print("#{indentention}Deleting #{a}")

  Delete.new(source: a).call

  @output.puts(" succeeded.")
end

#move(file: nil, directory: nil, as:, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/architecture/dsl.rb', line 29

def move(file: nil, directory: nil, as:, &block)
  a = Entity.new(id: directory || file, prefix: @source)
  b = Entity.new(id: as, prefix: @destination)

  @output.print("#{indentention}Moving #{a} to #{b}")

  Move.new(source: a, destination: b).call

  @output.puts(" succeeded.")

  if block_given? && directory
    within(directory: directory, &block)
  end
end

#overwrite(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/architecture/dsl.rb', line 99

def overwrite(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil)
  a = Entity.new(id: directory || file, prefix: location || @destination)

  @output.print("#{indentention}Appending #{a}")

  Overwrite.new(source: a, content: content, context: context).call

  @output.puts(" succeeded.")
end

#prepend(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/architecture/dsl.rb', line 78

def prepend(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil)
  a = Entity.new(id: file, prefix: location || @destination)

  @output.print("#{indentention}Prepending #{a} with content")


  Prepend.new(source: a, content: content, context: context).call

  @output.puts(" succeeded.")
end

#replace(file:, search:, content:, location: nil) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/architecture/dsl.rb', line 68

def replace(file:, search:, content:, location: nil)
  a = Entity.new(id: file, prefix: location || @destination)

  @output.print("#{indentention}Replacing content in #{a}")

  Replace.new(source: a, search: search, content: content).call

  @output.puts(" succeeded.")
end

#within(directory: nil, source: @source, destination: @destination, &block) ⇒ Object



109
110
111
112
113
# File 'lib/architecture/dsl.rb', line 109

def within(directory: nil, source: @source, destination: @destination, &block)
  @output.puts "#{indentention}Within #{join(directory || destination)}"

  self.class.new(source: join(@source, directory || source), destination:  join(@destination, directory || destination), output: @output, level: @level + 1, &block)
end