Class: PodspecEditor::Editor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Editor

Returns a new instance of Editor.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/podspec_editor.rb', line 50

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

Instance Attribute Details

#origin_json_contentObject

Returns the value of attribute origin_json_content.



38
39
40
# File 'lib/podspec_editor.rb', line 38

def origin_json_content
  @origin_json_content
end

#specObject

Returns the value of attribute spec.



39
40
41
# File 'lib/podspec_editor.rb', line 39

def spec
  @spec
end

Class Method Details

.default_json_spec_content(pod_name) ⇒ Object



41
42
43
44
# File 'lib/podspec_editor.rb', line 41

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

Instance Method Details

#current_hashObject



75
76
77
# File 'lib/podspec_editor.rb', line 75

def current_hash
  Helper.openstruct_to_hash(@spec.inner_spec)
end

#current_json_contentObject



79
80
81
# File 'lib/podspec_editor.rb', line 79

def current_json_content
  JSON.pretty_generate(current_hash)
end

#spec_to_json(spec_path) ⇒ Object



46
47
48
# File 'lib/podspec_editor.rb', line 46

def spec_to_json(spec_path)
  Pod::Specification.from_file(spec_path).to_pretty_json.chomp
end