defgen 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -49,6 +49,44 @@ The DSL should be pretty self explanatory call the `type` of the object followed
49
49
 
50
50
  ###Customisation
51
51
 
52
+ Sometimes you want to have a different getter so you can follow conventions like having a boolean `isValid` and `setValid:`, which sounds nicer than `isValid` and `setIsValid:`
53
+
54
+ Simple...
55
+
56
+ bool 'valid', :getter => 'isValid'
57
+
58
+ which generates
59
+
60
+ // NSUserDefaults+PASProperties.h
61
+
62
+ @property (nonatomic, assign, getter=pas_isValid) BOOL pas_valid;
63
+
64
+ // NSUserDefaults+PASProperties.m
65
+
66
+ - (BOOL)pas_isValid;
67
+ {
68
+ return [self boolForKey:PASValid];
69
+ }
70
+
71
+ - (void)setPas_valid:(BOOL)isValid;
72
+ {
73
+ [self setBool:isValid forKey:PASValid];
74
+ }
75
+
76
+ ---
77
+
78
+ If you don't like my choice of using `strong` for object properties you can override this in the same way
79
+
80
+ array 'colours', :ownership => :weak
81
+
82
+ which generates
83
+
84
+ // NSUserDefaults+PASProperties.h
85
+
86
+ @property (nonatomic, weak) NSArray *pas_colours;
87
+
88
+ ###Advanced Customisation
89
+
52
90
  If you don't like the supplied boiler plate then you can tweak it.
53
91
 
54
92
  ####Step 1. Call generate the stubs
@@ -143,8 +181,7 @@ This will generate the templates in your current project so that you can edit as
143
181
 
144
182
  ##Wish List
145
183
 
146
- - Support for provising customer getter e.g. `(nonatomic, strong, getter=isValid)`
147
- - Support for overriding ownership qualifiers
184
+ - Dry runs to show what will be generated
148
185
 
149
186
  ##Licence
150
187
 
data/lib/defgen/cli.rb CHANGED
@@ -11,10 +11,9 @@ module Defgen
11
11
 
12
12
  desc "parse", 'Parse a "Defaultfile" and modify the Xcodeproj'
13
13
  method_option :filename, default: 'Defaultfile',
14
- aliases: '-f',
15
- desc: 'Specify the input file path'
14
+ aliases: '-f',
15
+ desc: 'Specify the input file path'
16
16
  def parse
17
-
18
17
  path = Dir['*.xcodeproj'].first
19
18
 
20
19
  if path.nil?
@@ -10,6 +10,14 @@ module Defgen
10
10
  super.downcase
11
11
  end
12
12
 
13
+ def parameter
14
+ if attributes.getter.nil? || attributes.getter.empty?
15
+ super
16
+ else
17
+ attributes.getter
18
+ end
19
+ end
20
+
13
21
  def get_binding
14
22
  binding
15
23
  end
@@ -20,13 +20,14 @@ module Defgen
20
20
  [ 'double', 'double', 'double ', :assign, false ],
21
21
  [ 'url', 'URL', 'NSURL *', :strong, false ]
22
22
  ].each do |method_name, prefix, objc_type, ownership, object_setter|
23
- define_method method_name do |name|
23
+ define_method method_name do |name, options={}|
24
24
  Property.new do |property, attributes|
25
25
  property.name = name
26
26
  property.object_setter = object_setter
27
27
  property.message_prefix = prefix
28
28
  property.objc_type = objc_type
29
- attributes.ownership = ownership
29
+ attributes.ownership = options[:ownership] || ownership
30
+ attributes.getter = options[:getter]
30
31
 
31
32
  @properties << property
32
33
  end
@@ -5,6 +5,7 @@ module Defgen
5
5
 
6
6
  def initialize
7
7
  self.attributes = Attributes.new
8
+ self.attributes.property = self
8
9
  yield self, attributes if block_given?
9
10
  end
10
11
 
@@ -3,7 +3,7 @@ module Defgen
3
3
  class UnsupportedOwnershipError < ArgumentError; end
4
4
  class Attributes
5
5
  VALID_OWNERSHIPS = [:strong, :weak, :assign, :unsafe_unretained, :retain, :copy]
6
- attr_accessor :ownership
6
+ attr_accessor :ownership, :getter, :property
7
7
 
8
8
  def initialize
9
9
  @ownership = :strong
@@ -22,7 +22,13 @@ module Defgen
22
22
  end
23
23
 
24
24
  def to_s
25
- "(#{['nonatomic', ownership].compact.join(', ')})"
25
+ "(#{['nonatomic', ownership, formatted_getter].compact.join(', ')})"
26
+ end
27
+
28
+ def formatted_getter
29
+ unless getter.nil? || getter.empty?
30
+ "getter=#{property.prefix.downcase}_#{getter}"
31
+ end
26
32
  end
27
33
  end
28
34
  end
@@ -1,3 +1,3 @@
1
1
  module Defgen
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -27,5 +27,10 @@ module Defgen
27
27
  @property.prefix = 'PS'
28
28
  decorator.prefix.should eq('ps')
29
29
  end
30
+
31
+ it "uses a custom getter" do
32
+ @property.attributes.getter = 'isValid'
33
+ decorator.parameter.should eq('isValid')
34
+ end
30
35
  end
31
36
  end
@@ -38,5 +38,25 @@ module Defgen
38
38
  property.attributes.ownership.should eq(ownership)
39
39
  end
40
40
  end
41
+
42
+ it "can handle a custom getter" do
43
+ property = nil
44
+
45
+ expect do
46
+ property = defaultfile_parser.parse("bool 'valid', :getter => 'isValid'").first
47
+ end.to_not raise_error
48
+
49
+ property.attributes.getter.should eq('isValid')
50
+ end
51
+
52
+ it "can handle overriding ownership" do
53
+ property = nil
54
+
55
+ expect do
56
+ property = defaultfile_parser.parse("array 'myCollection', :ownership => :weak").first
57
+ end.to_not raise_error
58
+
59
+ property.attributes.ownership.should eq(:weak)
60
+ end
41
61
  end
42
62
  end
@@ -6,7 +6,9 @@ module Defgen
6
6
  describe Attributes do
7
7
  subject(:attributes) { Attributes.new }
8
8
 
9
+ it { should respond_to :property }
9
10
  it { should respond_to :ownership }
11
+ it { should respond_to :getter }
10
12
 
11
13
  Attributes::VALID_OWNERSHIPS.each do |semantic|
12
14
  it "creates the predicate method #{semantic}?" do
@@ -43,6 +45,13 @@ module Defgen
43
45
  attributes.to_s.should eq('(nonatomic)')
44
46
  end
45
47
  end
48
+
49
+ it "uses a custom getter" do
50
+ FakeProperty = Struct.new(:prefix)
51
+ attributes.property = FakeProperty.new('ps')
52
+ attributes.getter = 'isValid'
53
+ attributes.to_s.should eq('(nonatomic, strong, getter=ps_isValid)')
54
+ end
46
55
  end
47
56
  end
48
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: