Class: LockJar::Domain::Dsl

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

Direct Known Subclasses

JarfileDsl

Constant Summary collapse

DEFAULT_GROUP =
['default'].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDsl

Returns a new instance of Dsl.


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lock_jar/domain/dsl.rb', line 48

def initialize
  @remote_repositories = []
  @artifacts = { 'default' => [] }
  @group_changed = false
  @present_group = 'default'
  @local_repository = nil
  @maps = {}
  @excludes = []
  @merged = []
  @clear_repositories = false
end

Instance Attribute Details

#artifactsObject

Returns the value of attribute artifacts


26
27
28
# File 'lib/lock_jar/domain/dsl.rb', line 26

def artifacts
  @artifacts
end

#clear_repositoriesObject

Returns the value of attribute clear_repositories


26
27
28
# File 'lib/lock_jar/domain/dsl.rb', line 26

def clear_repositories
  @clear_repositories
end

#excludesObject

Returns the value of attribute excludes


26
27
28
# File 'lib/lock_jar/domain/dsl.rb', line 26

def excludes
  @excludes
end

#file_pathObject (readonly)

Returns the value of attribute file_path


29
30
31
# File 'lib/lock_jar/domain/dsl.rb', line 29

def file_path
  @file_path
end

#groupsObject

Returns the value of attribute groups


26
27
28
# File 'lib/lock_jar/domain/dsl.rb', line 26

def groups
  @groups
end

#local_repositoryObject Also known as: name

Returns the value of attribute local_repository


26
27
28
# File 'lib/lock_jar/domain/dsl.rb', line 26

def local_repository
  @local_repository
end

#mapsObject

Returns the value of attribute maps


26
27
28
# File 'lib/lock_jar/domain/dsl.rb', line 26

def maps
  @maps
end

#mergedObject

Returns the value of attribute merged


26
27
28
# File 'lib/lock_jar/domain/dsl.rb', line 26

def merged
  @merged
end

#remote_repositoriesObject

Returns the value of attribute remote_repositories


26
27
28
# File 'lib/lock_jar/domain/dsl.rb', line 26

def remote_repositories
  @remote_repositories
end

Class Method Details

.create(jarfile = nil, &blk) ⇒ Object


32
33
34
35
# File 'lib/lock_jar/domain/dsl.rb', line 32

def create(jarfile = nil, &blk)
  builder = new
  evaluate(builder, jarfile, &blk)
end

.evaluate(builder, jarfile = nil, &blk) ⇒ Object


37
38
39
40
41
42
43
44
45
# File 'lib/lock_jar/domain/dsl.rb', line 37

def evaluate(builder, jarfile = nil, &blk)
  fail 'jarfile or block must be set' if jarfile.nil? && blk.nil?

  builder.instance_eval(IO.read(jarfile.to_s), jarfile.to_s, 1) if jarfile

  builder.instance_eval(&blk) if blk

  builder
end

Instance Method Details

#exclude(*notations) ⇒ Object


60
61
62
# File 'lib/lock_jar/domain/dsl.rb', line 60

def exclude(*notations)
  @excludes += notations
end

#group(*groups, &_blk) ⇒ Object


124
125
126
127
128
129
130
131
132
# File 'lib/lock_jar/domain/dsl.rb', line 124

def group(*groups, &_blk)
  @group_changed = true
  groups.each do |group|
    @present_group = group.to_s
    yield
  end
  @group_changed = false
  @present_group = 'default'
end

#jar(notation, *args) ⇒ Object


64
65
66
67
68
69
70
71
72
# File 'lib/lock_jar/domain/dsl.rb', line 64

def jar(notation, *args)
  opts = {}

  opts.merge!(args.last) if args.last.is_a? Hash

  artifact = Jar.new(notation)

  assign_groups(artifact, opts[:group])
end

#local(*args) ⇒ Object


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/lock_jar/domain/dsl.rb', line 74

def local(*args)
  return if args.empty?

  if File.directory?(File.expand_path(args.first))
    warn(
      '[DEPRECATED] `local` to set local_repository is deprecated. '\
      'Please use `local_repo` instead'
    )
    local_repo(args.first)
  else
    path = args.shift

    opts = {}

    opts.merge!(args.last) if args.last.is_a? Hash

    artifact = Local.new(path)

    assign_groups(artifact, opts[:group])
  end
end

#local_repo(path) ⇒ Object


96
97
98
# File 'lib/lock_jar/domain/dsl.rb', line 96

def local_repo(path)
  @local_repository = path
end

#map(notation, *args) ⇒ Object

Map a dependency to another dependency or local directory.


103
104
105
# File 'lib/lock_jar/domain/dsl.rb', line 103

def map(notation, *args)
  @maps[notation] = args
end

#pom(path, *args) ⇒ Object


108
109
110
111
112
113
114
115
116
# File 'lib/lock_jar/domain/dsl.rb', line 108

def pom(path, *args)
  fail "#{path} is an invalid pom path" unless path =~ /\.xml$/i

  opts = { scopes: %w(runtime compile) }

  opts.merge!(args.last) if args.last.is_a? Hash

  assign_groups(Pom.new(path, opts[:scopes]), opts[:groups])
end

#remote_repo(url, _opts = {}) ⇒ Object Also known as: remote_repository, repository


118
119
120
# File 'lib/lock_jar/domain/dsl.rb', line 118

def remote_repo(url, _opts = {})
  @remote_repositories << url
end

#scope(*scopes, &blk) ⇒ Object

Deprecated.

Please use #group instead


135
136
137
138
# File 'lib/lock_jar/domain/dsl.rb', line 135

def scope(*scopes, &blk)
  warn '[DEPRECATED] `scope` is deprecated.  Please use `group` instead.'
  group(*scopes, &blk)
end

#without_default_maven_repoObject


140
141
142
# File 'lib/lock_jar/domain/dsl.rb', line 140

def without_default_maven_repo
  @clear_repositories = true
end