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.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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

Instance Attribute Details

#origin_json_contentObject

Returns the value of attribute origin_json_content.



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

def origin_json_content
  @origin_json_content
end

#specObject

Returns the value of attribute spec.



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

def spec
  @spec
end

Class Method Details

.default_json_spec_content(pod_name) ⇒ Object



40
41
42
43
# 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

Instance Method Details

#current_hashObject



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

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

#current_json_contentObject



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

def current_json_content
  JSON.pretty_generate(current_hash)
end

#spec_to_json(spec_path) ⇒ Object



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

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