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



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

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

  @output.print("#{indentention}Appending {#{truncate(a.path)}} with content")

  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 {#{truncate(a.path)}} to {#{truncate(b.path)}}")

  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 {#{truncate(a.path)}}")

  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 {#{truncate(a.path)}}")

  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 {#{truncate(a.path)}} to {#{truncate(b.path)}}")

  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



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

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

  @output.print("#{indentention}Overwriting {#{truncate(a.path)}} with content")

  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
# 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 {#{truncate(a.path)}} 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 {#{truncate(a.path)}}")

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

  @output.puts(" succeeded.")
end

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



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

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

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