Class: Steep::Project::DSL

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

Defined Under Namespace

Classes: TargetDSL

Constant Summary collapse

@@templates =
{
  gemfile: TargetDSL.new(:gemfile).tap do |target|
    target.check "Gemfile"
    target.library "gemfile"
  end
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:) ⇒ DSL

Returns a new instance of DSL.



86
87
88
89
# File 'lib/steep/project/dsl.rb', line 86

def initialize(project:)
  @project = project
  @global_signatures = []
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



73
74
75
# File 'lib/steep/project/dsl.rb', line 73

def project
  @project
end

Class Method Details

.parse(project, code, filename: "Steepfile") ⇒ Object



95
96
97
# File 'lib/steep/project/dsl.rb', line 95

def self.parse(project, code, filename: "Steepfile")
  self.new(project: project).instance_eval(code, filename)
end

.register_template(name, target) ⇒ Object



91
92
93
# File 'lib/steep/project/dsl.rb', line 91

def self.register_template(name, target)
  templates[name] = target
end

.templatesObject



82
83
84
# File 'lib/steep/project/dsl.rb', line 82

def self.templates
  @@templates
end

Instance Method Details

#target(name, template: nil, &block) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/steep/project/dsl.rb', line 99

def target(name, template: nil, &block)
  target = if template
             self.class.templates[template]&.dup&.update(name: name) or
               raise "Unknown template: #{template}, available templates: #{@@templates.keys.join(", ")}"
           else
             TargetDSL.new(name)
           end

  target.instance_eval(&block) if block_given?

  Project::Target.new(
    name: target.name,
    source_patterns: target.sources,
    ignore_patterns: target.ignored_sources,
    signature_patterns: target.signatures,
    options: Options.new.tap do |options|
      options.libraries.push(*target.libraries)

      case target.vendor_dir
      when Array
        options.vendored_stdlib_path = target.vendor_dir[0]
        options.vendored_gems_path = target.vendor_dir[1]
      when Pathname
        options.vendored_stdlib_path = target.vendor_dir + "stdlib"
        options.vendored_gems_path = target.vendor_dir + "gems"
      end
    end
  ).tap do |target|
    project.targets << target
  end
end