jsoncop 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a59d17ecb175894205580ffe2427ac85c4eb052b
4
- data.tar.gz: b720d5fc5bdcd7b51881eceec0392a0360a2eb0f
3
+ metadata.gz: fe2dadd4db52fbf4f373d7219133ee6a400c3c61
4
+ data.tar.gz: e7ce11ffaa6a534e095b73d5301e6f04a622181d
5
5
  SHA512:
6
- metadata.gz: 44e6fff44d7d366e14af38c2694b6472208de94896a6cad5291f1a7852f7f136f1557f0b760fec7b3955e387de188cf9c051477c9bf2591a0a629b5fbd40adee
7
- data.tar.gz: a2386cf061216c2dd79f4103ead2490bb411138ac1cd1c52aafe9254d96cfeac6cf12a58b2680d065546417e1df591f696db86d7808d6ead63dc48efb09d9753
6
+ metadata.gz: ae267be67d57306b869c5e5bc267691941d3a4ea25dfff9188d322646da8e6d1187cb8d8268a841442c5fe5d965e55cc407e23470219e15c8bac12528eebc290
7
+ data.tar.gz: d1bbf93c5b176cf40c734113727e09068c0b2e2ee0d16b582a59858add6554023af9941350c096c140d2579ba63914092b575a7a493455d66aef0be66969caf9
data/README.md CHANGED
@@ -1,31 +1,72 @@
1
1
  # JSONCop
2
2
 
3
+ [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/draveness/jsoncop/blob/master/LICENSE)
4
+ [![Gem](https://img.shields.io/gem/v/jsoncop.svg?style=flat)](http://rubygems.org/gems/jsoncop)
5
+ [![Swift](https://img.shields.io/badge/swift-3.0-yellow.svg)](https://img.shields.io/badge/Swift-%203.0%20-yellow.svg)
6
+
3
7
  JSONCop makes it easy to write a simple model layer for your Cocoa and Cocoa Touch application.
4
8
 
5
- > JSONCop's APIs are highly inspired by [Mantle](https://github.com/Mantle/Mantle)
9
+ > JSONCop's APIs are highly inspired by [Mantle](https://github.com/Mantle/Mantle), you can use similar APIs to generate parsing methods with JSONCop.
6
10
 
7
- ## Installation
11
+ ```swift
12
+ let json: [String: Any] = [
13
+ "id": 1,
14
+ "name": "Draven",
15
+ "createdAt": NSTimeIntervalSince1970
16
+ ]
17
+ let person = Person.parse(json: json)
18
+ ```
8
19
 
9
- Add this line to your application's Gemfile:
20
+ ## Usage
10
21
 
11
- ```ruby
12
- gem 'jsoncop'
22
+ Define a model with and implement `static func JSONKeyPathByPropertyKey` method:
23
+
24
+ ```swift
25
+ // jsoncop: enabled
26
+
27
+ struct Person {
28
+ let id: Int
29
+ let name: String
30
+ let createdAt: Date
31
+
32
+ static func JSONKeyPathByPropertyKey() -> [String: String] {
33
+ return [
34
+ "id": "id",
35
+ "name": "name",
36
+ "createdAt": "createdAt"
37
+ ]
38
+ }
39
+
40
+ static func createdAtJSONTransformer(value: Any) -> Date? {
41
+ guard let value = value as? Double else { return nil }
42
+ return Date(timeIntervalSinceNow: value)
43
+ }
44
+ }
13
45
  ```
14
46
 
15
- And then execute:
47
+ > DO NOT forget to add "// jsoncop: enabled" before struct.
16
48
 
17
- $ bundle
49
+ Run `cop install` in project root folder.
18
50
 
19
- Or install it yourself as:
51
+ ```shell
52
+ $ cop install
53
+ ```
20
54
 
21
- $ gem install jsoncop
55
+ This will generate several parsing methods in current file:
22
56
 
23
- ## Usage
57
+ ![](./images/jsoncop-demo.png)
24
58
 
59
+ All the code between `generate-start` and `generate-end` and will be replaced when re-run `cop install` in current project folder. Other codes will remain unchanged. Please don't write any codes in this area.
60
+
61
+ ## Installation
62
+
63
+ ```
64
+ sudo gem install jsoncop --verbose
65
+ ```
25
66
 
26
67
  ## Contributing
27
68
 
28
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jsoncop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/draveness/jsoncop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
29
70
 
30
71
 
31
72
  ## License
@@ -1,6 +1,6 @@
1
1
  module JSONCop
2
2
  class Command
3
- class Deintegrate < Command
3
+ class Uninstall < Command
4
4
  self.summary = ""
5
5
  self.description = <<-DESC
6
6
  DESC
@@ -10,6 +10,15 @@ module JSONCop
10
10
  end
11
11
 
12
12
  def run
13
+ Dir.glob("**/*.swift").each do |file_path|
14
+ jsoncop_generate_start = /jsoncop: generate\-start/
15
+ jsoncop_generate_end = /jsoncop: generate\-end/
16
+ content = File.read file_path
17
+ if content.match(jsoncop_generate_start) && content.match(jsoncop_generate_end)
18
+ content.gsub!(/\/\/ jsoncop: generate-start[^$]*jsoncop: generate\-end/, "")
19
+ end
20
+ File.write file_path, content
21
+ end
13
22
  end
14
23
  end
15
24
  end
@@ -13,18 +13,18 @@ module JSONCop
13
13
  end
14
14
 
15
15
  def generate!
16
- jsoncop_generated_start = /jsoncop: generated\-start/
17
- jsoncop_generated_end = /jsoncop: generated\-end/
16
+ jsoncop_generate_start = /jsoncop: generate\-start/
17
+ jsoncop_generate_end = /jsoncop: generate\-end/
18
18
  content = File.read file_path
19
- if content.match(jsoncop_generated_start) && content.match(jsoncop_generated_end)
20
- content.gsub!(/\/\/ jsoncop: generated-start[^$]*jsoncop: generated\-end/, "")
19
+ if content.match(jsoncop_generate_start) && content.match(jsoncop_generate_end)
20
+ content.gsub!(/\/\/ jsoncop: generate-start[^$]*jsoncop: generate\-end/, "")
21
21
  end
22
22
  File.write file_path, content + json_cop_template
23
23
  end
24
24
 
25
25
  def json_cop_template
26
26
  <<-JSONCOP
27
- // jsoncop: generated-start
27
+ // jsoncop: generate-start
28
28
 
29
29
  extension #{@model.name} {
30
30
  static func parse(json: [String: Any]) -> #{@model.name}? {
@@ -36,7 +36,7 @@ extension #{@model.name} {
36
36
  }
37
37
  }
38
38
 
39
- // jsoncop: generated-end
39
+ // jsoncop: generate-end
40
40
  JSONCOP
41
41
  end
42
42
 
@@ -1,3 +1,3 @@
1
1
  module JSONCop
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsoncop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Draveness