property_synthesize_dealloc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +58 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/lib/config.yml +14 -0
- data/lib/configuration.rb +24 -0
- data/lib/content_replacer.rb +74 -0
- data/lib/converter.rb +55 -0
- data/lib/file_checker.rb +48 -0
- data/lib/property_synthesize_dealloc.rb +113 -0
- data/spec/property_synthesize_dealloc_spec.rb +92 -0
- data/spec/spec_helper.rb +12 -0
- metadata +184 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm ree@property_synthesize_dealloc
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rb-appscript", ">= 0.6.0"
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development do
|
8
|
+
gem "rspec"
|
9
|
+
gem "yard"
|
10
|
+
gem "bundler"
|
11
|
+
gem "jeweler"
|
12
|
+
gem "rcov"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.8.7)
|
11
|
+
rb-appscript (0.6.0)
|
12
|
+
rcov (0.9.9)
|
13
|
+
rspec (2.5.0)
|
14
|
+
rspec-core (~> 2.5.0)
|
15
|
+
rspec-expectations (~> 2.5.0)
|
16
|
+
rspec-mocks (~> 2.5.0)
|
17
|
+
rspec-core (2.5.1)
|
18
|
+
rspec-expectations (2.5.0)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
rspec-mocks (2.5.0)
|
21
|
+
yard (0.6.4)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
bundler
|
28
|
+
jeweler
|
29
|
+
rb-appscript (>= 0.6.0)
|
30
|
+
rcov
|
31
|
+
rspec
|
32
|
+
yard
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Craig Williams
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Description #
|
2
|
+
|
3
|
+
One of the things we do a lot of in Objective-C is outlet and variable declaration, synthesize and dealloc. Since this is a repeatable recurring event I thought I would add a little automation to the process.
|
4
|
+
|
5
|
+
# Instructions #
|
6
|
+
|
7
|
+
Install the gem.
|
8
|
+
_I have only been able to get this working in Xcode by installing the gem in system ruby._
|
9
|
+
|
10
|
+
sudo gem install property_synthesize_dealloc
|
11
|
+
|
12
|
+
Make a user script in Xcode with the following:
|
13
|
+
|
14
|
+
#!/usr/bin/ruby
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require "property_synthesize_dealloc"
|
18
|
+
|
19
|
+
property = PropertySynthesizeDealloc.new
|
20
|
+
property.file_path = '%%%{PBXFilePath}%%%'
|
21
|
+
property.selection = STDIN.read
|
22
|
+
property.psd!
|
23
|
+
|
24
|
+
Then select the ivars you wish to make property, synthesize and dealloc declarations and execute the user script above.
|
25
|
+
|
26
|
+
|
27
|
+
# Overriding defaults #
|
28
|
+
|
29
|
+
You can provide an optional parameter to a custom config.yml file.
|
30
|
+
Just add the path as a parameter to PropertySynthesizeDealloc.new.
|
31
|
+
|
32
|
+
PropertySynthesizeDealloc.new("/path/to/custom/config.yml")
|
33
|
+
|
34
|
+
|
35
|
+
Here is the skeleton. Make sure to use this as a starting point.
|
36
|
+
These are currently the only options supported.
|
37
|
+
|
38
|
+
settings:
|
39
|
+
sleep_time: 0.1
|
40
|
+
xcode_app_path: '/Developer/Applications/Xcode.app'
|
41
|
+
use_nonatomic: true
|
42
|
+
position_prop_after_closing_bracket: false
|
43
|
+
outlet: true
|
44
|
+
|
45
|
+
types:
|
46
|
+
copy: ['NSString', 'NSMutableString', 'NSArray', 'NSNumber']
|
47
|
+
assign: ['int', 'integer', 'BOOL', 'float', 'NSUInteger', 'NSInteger',
|
48
|
+
'double', 'uint8_t', 'uint16_t', 'uint32_t', 'int8_t', 'int16_t',
|
49
|
+
'int32_t', 'int64_t', 'uint64_t', 'GLuint', 'GLushort', 'GLubyte',
|
50
|
+
'GLfloat', 'size_t', 'GLenum']
|
51
|
+
retain: []
|
52
|
+
|
53
|
+
|
54
|
+
### Copyright
|
55
|
+
|
56
|
+
Copyright (c) 2011 Craig Williams. See LICENSE.txt for
|
57
|
+
further details.
|
58
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
gem.name = "property_synthesize_dealloc"
|
15
|
+
gem.homepage = "http://github.com/CraigWilliams/property_synthesize_dealloc"
|
16
|
+
gem.license = "MIT"
|
17
|
+
gem.summary = %Q{Creates property, synthesize and dealloc statements from selected ivar declarations}
|
18
|
+
gem.description = %Q{Creates property, synthesize and dealloc statements from selected ivar declarations for the header and implementation files in an Xcode project.}
|
19
|
+
gem.email = "cwilliams.allancraig@gmail.com"
|
20
|
+
gem.authors = ["Craig Williams"]
|
21
|
+
gem.add_runtime_dependency 'rb-appscript', '>= 0.6.0'
|
22
|
+
end
|
23
|
+
Jeweler::RubygemsDotOrgTasks.new
|
24
|
+
|
25
|
+
require 'rspec/core'
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
28
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'yard'
|
39
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/config.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
settings:
|
2
|
+
sleep_time: 0.1
|
3
|
+
xcode_app_path: '/Developer/Applications/Xcode.app'
|
4
|
+
use_nonatomic: true
|
5
|
+
position_prop_after_closing_bracket: false
|
6
|
+
outlet: true
|
7
|
+
|
8
|
+
types:
|
9
|
+
copy: ['NSString', 'NSMutableString', 'NSArray', 'NSNumber']
|
10
|
+
assign: ['int', 'integer', 'BOOL', 'float', 'NSUInteger', 'NSInteger',
|
11
|
+
'double', 'uint8_t', 'uint16_t', 'uint32_t', 'int8_t', 'int16_t',
|
12
|
+
'int32_t', 'int64_t', 'uint64_t', 'GLuint', 'GLushort', 'GLubyte',
|
13
|
+
'GLfloat', 'size_t', 'GLenum']
|
14
|
+
retain: []
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "yaml"
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
class Configuration
|
6
|
+
@@settings = ''
|
7
|
+
@@types = ''
|
8
|
+
@@config = nil
|
9
|
+
|
10
|
+
def initialize(path='')
|
11
|
+
path = File.join(File.dirname(__FILE__), "config.yml") if path.empty?
|
12
|
+
configuration = OpenStruct.new YAML.load_file(path)
|
13
|
+
@@settings = configuration.settings
|
14
|
+
@@types = configuration.types
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.settings
|
18
|
+
@@settings
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.types
|
22
|
+
@@types
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.join File.dirname(__FILE__), "configuration"
|
2
|
+
|
3
|
+
class ContentReplacer
|
4
|
+
|
5
|
+
def initialize(converter)
|
6
|
+
@synthesize = converter.synthesize
|
7
|
+
@properties = converter.properties
|
8
|
+
@release = converter.release
|
9
|
+
@unload = converter.unload
|
10
|
+
@position_prop_after_closing_bracket = Configuration.settings['position_prop_after_closing_bracket']
|
11
|
+
end
|
12
|
+
|
13
|
+
#==============================================================
|
14
|
+
# Reading and updating the .m file contents
|
15
|
+
#==============================================================
|
16
|
+
def m_content(file_path)
|
17
|
+
mFileContents = IO.read(file_path)
|
18
|
+
updatedFileContents = ''
|
19
|
+
mFileContents.split("\n").each do |line|
|
20
|
+
if line =~ /^@implementation/
|
21
|
+
updatedFileContents << line + "\n" + @synthesize.chomp
|
22
|
+
elsif line =~ /\[super dealloc\]/
|
23
|
+
updatedFileContents << @release.chomp + "\n" + line
|
24
|
+
elsif line =~ /\(void\)\s?viewDidUnload/
|
25
|
+
updatedFileContents << line + "\n" + @unload.chomp
|
26
|
+
else
|
27
|
+
updatedFileContents << line
|
28
|
+
end
|
29
|
+
updatedFileContents << "\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
updatedFileContents
|
33
|
+
end
|
34
|
+
|
35
|
+
#==============================================================
|
36
|
+
# Reading and updating the .h file contents
|
37
|
+
#==============================================================
|
38
|
+
def header_content(file_path)
|
39
|
+
if @position_prop_after_closing_bracket
|
40
|
+
next_bracket = false
|
41
|
+
hFileContents = IO.read(file_path)
|
42
|
+
updatedHFileContents = ''
|
43
|
+
hFileContents.split("\n").each do |line|
|
44
|
+
next_bracket = true if line =~ /^@interface/
|
45
|
+
|
46
|
+
if line =~ /^\}/ && next_bracket
|
47
|
+
next_bracket = false
|
48
|
+
updatedHFileContents << line + "\n" + @properties.chomp
|
49
|
+
else
|
50
|
+
updatedHFileContents << line
|
51
|
+
end
|
52
|
+
updatedHFileContents << "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
else
|
56
|
+
|
57
|
+
next_bracket = false
|
58
|
+
hFileContents = IO.read(file_path)
|
59
|
+
updatedHFileContents = ''
|
60
|
+
hFileContents.split("\n").each do |line|
|
61
|
+
next_bracket = true if line =~ /^@interface/
|
62
|
+
|
63
|
+
if line =~ /^\@end/ && next_bracket
|
64
|
+
next_bracket = false
|
65
|
+
updatedHFileContents << @properties.chomp + "\n" + line
|
66
|
+
else
|
67
|
+
updatedHFileContents << line
|
68
|
+
end
|
69
|
+
updatedHFileContents << "\n"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
updatedHFileContents
|
73
|
+
end
|
74
|
+
end
|
data/lib/converter.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.join File.dirname(__FILE__), "configuration"
|
2
|
+
|
3
|
+
class Converter
|
4
|
+
attr_accessor :properties, :synthesize, :release, :unload
|
5
|
+
|
6
|
+
def initialize(selection)
|
7
|
+
@properties = ''
|
8
|
+
@synthesize = ''
|
9
|
+
@release = ''
|
10
|
+
@unload = ''
|
11
|
+
@selection = selection
|
12
|
+
|
13
|
+
@copy = Configuration.types['copy']
|
14
|
+
@assign = Configuration.types['assign']
|
15
|
+
@use_nonatomic = Configuration.settings['use_nonatomic']
|
16
|
+
@outlet = Configuration.settings['outlet']
|
17
|
+
end
|
18
|
+
|
19
|
+
def convert
|
20
|
+
@selection.split("\n").each do |line|
|
21
|
+
line = line.scan("*") == [] ? line.strip : line.gsub!(/\*/, '').strip
|
22
|
+
words = line.split(/\s+/)
|
23
|
+
label = words.size > 2 ? words[1] : words[0]
|
24
|
+
variable = words[-1]
|
25
|
+
mem_label = memory_management(label)
|
26
|
+
star = mem_label == 'assign' ? '' : '*'
|
27
|
+
|
28
|
+
@properties << "@property (#{use_nonatomic(mem_label)}) #{("IBOutlet " if @outlet)}#{label} #{star}#{variable}\n"
|
29
|
+
@synthesize << "@synthesize #{variable}\n"
|
30
|
+
@release << "\t[self set#{cap_first_letter_of(variable).chomp}:nil];\n" unless mem_label == 'assign'
|
31
|
+
@unload << "\t[self set#{cap_first_letter_of(variable).chomp}:nil];\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def log(msg)
|
38
|
+
File.open(File.expand_path("~/desktop/errors.txt"), 'a+') { |f| f.puts msg + "\n" }
|
39
|
+
end
|
40
|
+
|
41
|
+
def memory_management(label)
|
42
|
+
return "copy" if @copy.include?(label)
|
43
|
+
return "assign" if @assign.include?(label)
|
44
|
+
return "retain"
|
45
|
+
end
|
46
|
+
|
47
|
+
def use_nonatomic(mem_label)
|
48
|
+
return @use_nonatomic ? "nonatomic, #{mem_label}" : mem_label
|
49
|
+
end
|
50
|
+
|
51
|
+
def cap_first_letter_of(word)
|
52
|
+
word[0] = word[0,1].upcase
|
53
|
+
word
|
54
|
+
end
|
55
|
+
end
|
data/lib/file_checker.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class FileChecker
|
2
|
+
attr_accessor :error_msg, :path_ok, :path_to_check, :header_path, :implementation_path
|
3
|
+
|
4
|
+
def initialize(path)
|
5
|
+
@path_to_check = path
|
6
|
+
@header_path = path
|
7
|
+
@implementation_path = nil
|
8
|
+
@error_msg = []
|
9
|
+
@path_ok = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_file_path
|
13
|
+
unless valid_header_file?
|
14
|
+
@path_ok = false
|
15
|
+
@error_msg << "This is not a header file."
|
16
|
+
end
|
17
|
+
|
18
|
+
unless valid_implementation_file?
|
19
|
+
@path_ok = false
|
20
|
+
@error_msg << "There is no implementation file for this header file."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def valid_header_file?
|
27
|
+
File.extname(@path_to_check) == '.h'
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_implementation_file?
|
31
|
+
parent = File.dirname(@path_to_check)
|
32
|
+
file_name = File.basename(@path_to_check, '.*')
|
33
|
+
m_path = File.join(parent, file_name + '.m')
|
34
|
+
|
35
|
+
# Check for an implementation file and if one
|
36
|
+
# does not exist, check for a ".mm" file
|
37
|
+
if File.exists?(m_path)
|
38
|
+
@implementation_path = m_path
|
39
|
+
elsif File.exists?(m_path << "m")
|
40
|
+
@implementation_path = m_path << 'm'
|
41
|
+
else
|
42
|
+
@implementation_path = nil
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "appscript"; include Appscript
|
5
|
+
require 'osax'; include OSAX
|
6
|
+
require "file_checker"
|
7
|
+
require 'configuration'
|
8
|
+
require "converter"
|
9
|
+
require "content_replacer"
|
10
|
+
|
11
|
+
class PropertySynthesizeDealloc
|
12
|
+
attr_accessor :xcode, :file_path, :selection, :header_file_path, :m_file_path, :config_path
|
13
|
+
|
14
|
+
def initialize(config_file_path='')
|
15
|
+
Configuration.new(config_file_path)
|
16
|
+
|
17
|
+
@sleep_time = Configuration.settings['sleep_time']
|
18
|
+
@xcode = app(Configuration.settings['xcode_app_path'])
|
19
|
+
@file_path = file_path
|
20
|
+
end
|
21
|
+
|
22
|
+
def psd!
|
23
|
+
selection_check
|
24
|
+
file_check
|
25
|
+
|
26
|
+
converter = convert_selection
|
27
|
+
content_replacer = ContentReplacer.new(converter)
|
28
|
+
header_content = content_replacer.header_content(@header_file_path)
|
29
|
+
m_content = content_replacer.m_content(@m_file_path)
|
30
|
+
|
31
|
+
# Update the files!
|
32
|
+
replace_file_content(@header_file_path, header_content)
|
33
|
+
replace_file_content(@m_file_path, m_content)
|
34
|
+
end
|
35
|
+
|
36
|
+
def convert_selection
|
37
|
+
converter = Converter.new(@selection)
|
38
|
+
converter.convert
|
39
|
+
converter
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def log(msg)
|
46
|
+
File.open(File.expand_path("~/desktop/errors.txt"), 'a+') { |f| f.puts msg + "\n" }
|
47
|
+
end
|
48
|
+
|
49
|
+
def dialog(msg)
|
50
|
+
osax.display_dialog(msg,
|
51
|
+
:buttons => ["Ok"],
|
52
|
+
:default_button => 1)
|
53
|
+
end
|
54
|
+
|
55
|
+
def replace_file_content(path, content)
|
56
|
+
@xcode.open(path)
|
57
|
+
sleep @sleep_time
|
58
|
+
if doc = find_and_save_file(path)
|
59
|
+
doc.contents.set(content)
|
60
|
+
doc.save
|
61
|
+
return true
|
62
|
+
end
|
63
|
+
return false
|
64
|
+
end
|
65
|
+
|
66
|
+
def selection_check
|
67
|
+
# exit if nothing is selected
|
68
|
+
if @selection.empty?
|
69
|
+
dialog "There is nothing selected to convert."
|
70
|
+
exit!
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def file_check
|
75
|
+
file_path_supplied?
|
76
|
+
save_current_file
|
77
|
+
find_and_save_file
|
78
|
+
|
79
|
+
file_checker = FileChecker.new(@file_path)
|
80
|
+
file_checker.check_file_path
|
81
|
+
if file_checker.path_ok == false
|
82
|
+
dialog file_checker.error_msg.join("\n")
|
83
|
+
exit!
|
84
|
+
else
|
85
|
+
@header_file_path = file_checker.header_path
|
86
|
+
@m_file_path = file_checker.implementation_path
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def file_path_supplied?
|
91
|
+
if !@file_path
|
92
|
+
dialog "You have not supplied a file path"
|
93
|
+
exit!
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def save_current_file
|
98
|
+
@xcode.text_documents[1].save
|
99
|
+
end
|
100
|
+
|
101
|
+
def find_and_save_file(file_path=@file_path)
|
102
|
+
docs = @xcode.text_documents.get
|
103
|
+
docs.each do |doc|
|
104
|
+
path = doc.get.file_name.get
|
105
|
+
if file_path == path
|
106
|
+
doc.save
|
107
|
+
return doc
|
108
|
+
else
|
109
|
+
false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
# property = PropertySynthesizeDealloc.new
|
4
|
+
# property.file_path = '%%%{PBXFilePath}%%%'
|
5
|
+
# property.selection = STDIN.read
|
6
|
+
# property.psd!
|
7
|
+
|
8
|
+
describe "PropertySynthesizeDealloc" do
|
9
|
+
|
10
|
+
context "initialization" do
|
11
|
+
let(:p) { PropertySynthesizeDealloc.new }
|
12
|
+
let(:config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', 'lib', 'config.yml')) }
|
13
|
+
|
14
|
+
it "should create a new instance of class" do
|
15
|
+
p.should be_kind_of(PropertySynthesizeDealloc)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have Configuration settings when initialized" do
|
19
|
+
Configuration.settings['sleep_time'].should == config['settings']['sleep_time']
|
20
|
+
Configuration.settings['xcode_app_path'].should == config['settings']['xcode_app_path']
|
21
|
+
Configuration.settings['use_nonatomic'].should == config['settings']['use_nonatomic']
|
22
|
+
Configuration.settings['position_prop_after_closing_bracket'].should == config['settings']['position_prop_after_closing_bracket']
|
23
|
+
Configuration.settings['outlet'].should == config['settings']['outlet']
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have Configuration types when initialized" do
|
27
|
+
Configuration.types['copy'].should == config['types']['copy']
|
28
|
+
Configuration.types['assign'].should == config['types']['assign']
|
29
|
+
Configuration.types['retain'].should == config['types']['retain']
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be able to set a file path" do
|
33
|
+
path = '/some/random/path.h'
|
34
|
+
p.file_path = path
|
35
|
+
p.file_path.should == path
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should exit if no file path provided" do
|
39
|
+
pending "stubbing a dialog not working" do
|
40
|
+
dialog = mock('dialog').as_null_object
|
41
|
+
OSAX.osax.stub!(:display_dialog).with('"You have not supplied a file path", ({:buttons=>["Ok"], :default_button=>1}').and_return(dialog)
|
42
|
+
|
43
|
+
p.selection = "NSString *string"
|
44
|
+
p.psd!.should == dialog
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should exit if nothing is selected" do
|
49
|
+
pending "stubbing a dialog not working" do
|
50
|
+
dialog = mock('dialog').as_null_object
|
51
|
+
OSAX.osax.stub!(:display_dialog).with('"There is nothing selected to convert.", ({:buttons=>["Ok"], :default_button=>1}').and_return(dialog)
|
52
|
+
|
53
|
+
p.psd!.should == dialog
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
context "converting selected text" do
|
60
|
+
|
61
|
+
let(:p) { PropertySynthesizeDealloc.new }
|
62
|
+
|
63
|
+
before do
|
64
|
+
p.file_path = "/random/path.h"
|
65
|
+
p.selection = "NSString *string\nNSArray *array\nNSMutableArray *theMutableArray"
|
66
|
+
@converter = p.convert_selection
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should convert properties correctly" do
|
70
|
+
res = "@property (nonatomic, copy) IBOutlet NSString *string\n@property (nonatomic, copy) IBOutlet NSArray *array\n@property (nonatomic, retain) IBOutlet NSMutableArray *theMutableArray\n"
|
71
|
+
@converter.properties.should == res
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should convert synthensize correctly" do
|
75
|
+
res = "@synthesize string\n@synthesize array\n@synthesize theMutableArray\n"
|
76
|
+
@converter.synthesize.should == res
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should convert release correctly" do
|
80
|
+
res = "\t[self setString:nil];\n\t[self setArray:nil];\n\t[self setTheMutableArray:nil];\n"
|
81
|
+
@converter.release.should == res
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should convert unload correctly" do
|
85
|
+
res = "\t[self setString:nil];\n\t[self setArray:nil];\n\t[self setTheMutableArray:nil];\n"
|
86
|
+
@converter.unload.should == res
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'property_synthesize_dealloc'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: property_synthesize_dealloc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Craig Williams
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-27 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rb-appscript
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 6
|
32
|
+
- 0
|
33
|
+
version: 0.6.0
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
requirement: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: yard
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
requirement: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: bundler
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
requirement: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: jeweler
|
81
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
prerelease: false
|
91
|
+
type: :development
|
92
|
+
requirement: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: rcov
|
95
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
prerelease: false
|
105
|
+
type: :development
|
106
|
+
requirement: *id006
|
107
|
+
- !ruby/object:Gem::Dependency
|
108
|
+
name: rb-appscript
|
109
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 7
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
- 6
|
118
|
+
- 0
|
119
|
+
version: 0.6.0
|
120
|
+
prerelease: false
|
121
|
+
type: :runtime
|
122
|
+
requirement: *id007
|
123
|
+
description: Creates property, synthesize and dealloc statements from selected ivar declarations for the header and implementation files in an Xcode project.
|
124
|
+
email: cwilliams.allancraig@gmail.com
|
125
|
+
executables: []
|
126
|
+
|
127
|
+
extensions: []
|
128
|
+
|
129
|
+
extra_rdoc_files:
|
130
|
+
- LICENSE.txt
|
131
|
+
- README.markdown
|
132
|
+
files:
|
133
|
+
- .rvmrc
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.markdown
|
138
|
+
- Rakefile
|
139
|
+
- VERSION
|
140
|
+
- lib/config.yml
|
141
|
+
- lib/configuration.rb
|
142
|
+
- lib/content_replacer.rb
|
143
|
+
- lib/converter.rb
|
144
|
+
- lib/file_checker.rb
|
145
|
+
- lib/property_synthesize_dealloc.rb
|
146
|
+
- spec/property_synthesize_dealloc_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
has_rdoc: true
|
149
|
+
homepage: http://github.com/CraigWilliams/property_synthesize_dealloc
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
hash: 3
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
version: "0"
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
hash: 3
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
version: "0"
|
175
|
+
requirements: []
|
176
|
+
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 1.5.0
|
179
|
+
signing_key:
|
180
|
+
specification_version: 3
|
181
|
+
summary: Creates property, synthesize and dealloc statements from selected ivar declarations
|
182
|
+
test_files:
|
183
|
+
- spec/property_synthesize_dealloc_spec.rb
|
184
|
+
- spec/spec_helper.rb
|