class PodspecEditor::Editor

Attributes

origin_json_content[RW]
spec[RW]

Public Class Methods

default_json_spec_content(pod_name) click to toggle source
# File lib/podspec/editor.rb, line 40
def self.default_json_spec_content(pod_name)
  content = File.read(File.expand_path('TEMPLATE.podspec.json', __dir__))
  content.gsub('POD_NAME', pod_name)
end
new(args) click to toggle source
# File lib/podspec/editor.rb, line 49
def initialize(args)
  json_path = args[:json_path]
  if json_path
    unless Pathname.new(json_path).exist?
      raise ArgumentError, "invalid json path #{json_path}"
    end

    @origin_json_content = File.read(json_path).chomp
  end

  json_content = args[:json_content]
  @origin_json_content = json_content if json_content

  spec_path = args[:spec_path]
  if spec_path
    unless Pathname.new(spec_path).exist?
      raise ArgumentError, "invalid spec path #{spec_path}"
    end

    @origin_json_content = spec_to_json spec_path
  end

  @spec = Spec.new @origin_json_content
end

Public Instance Methods

current_hash() click to toggle source
# File lib/podspec/editor.rb, line 74
def current_hash
  Helper.openstruct_to_hash(@spec.inner_spec)
end
current_json_content() click to toggle source
# File lib/podspec/editor.rb, line 78
def current_json_content
  JSON.pretty_generate(current_hash)
end
spec_to_json(spec_path) click to toggle source
# File lib/podspec/editor.rb, line 45
def spec_to_json(spec_path)
  Pod::Specification.from_file(spec_path).to_pretty_json.chomp
end