parse-model-scaffold 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ parse-model-scaffold (0.0.1)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ httparty (0.11.0)
11
+ multi_json (~> 1.0)
12
+ multi_xml (>= 0.5.2)
13
+ multi_json (1.7.3)
14
+ multi_xml (0.5.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ parse-model-scaffold!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Matt Hupman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ parse-model-scaffold
2
+ ====================
3
+
4
+ This project is a work in progress!
5
+
6
+ Currently supported languages are Coffeescript (```:coffee```) and Objective-c (```:objc```). PFScaffolder will generate all languages by default.
7
+
8
+ Usage
9
+ =====
10
+
11
+ ```bash
12
+ gem install parse-model-scaffold
13
+ ```
14
+
15
+ ```ruby
16
+ require 'parse_model_generator'
17
+
18
+ scaffolder = Parse::Model::Scaffold::PFScaffolder.new 'parse_app_id', 'parse_api_key'
19
+
20
+ scaffolder.generate 'ParseClassName'
21
+ scaffolder.generate ['ParseClassName1', 'ParseClassName2']
22
+ scaffolder.generate ['ParseClassName1', 'ParseClassName2'], [:objc]
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ require 'httparty'
2
+
3
+ module Parse
4
+ module Model
5
+ module Scaffold
6
+
7
+ class ParseApi
8
+ include HTTParty
9
+ base_uri 'https://api.parse.com/1/classes'
10
+
11
+ def initialize(appId, apiKey)
12
+ headers = {'X-Parse-Application-Id' => appId, 'X-Parse-REST-API-Key' => apiKey}
13
+ @options = {:headers => headers}
14
+ end
15
+
16
+ def get_first(class_name)
17
+ response = self.class.get("/#{class_name}", @options.merge({:query => {:limit => 1}}))
18
+
19
+ response['results'][0]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ require 'erb'
2
+
3
+ module Parse
4
+ module Model
5
+ module Scaffold
6
+
7
+ class ParseClassBuilder
8
+
9
+ @@supported_types = [:coffee, :objc]
10
+
11
+ def initialize (class_name, attrs)
12
+ @class_name = class_name
13
+ @attrs = attrs
14
+ end
15
+
16
+ def build (types = nil)
17
+
18
+ types ||= supported_types
19
+
20
+ types.each do |type|
21
+
22
+ templates = Dir.glob "./lib/parse-model-scaffold/templates/#{type}/*.ejs"
23
+
24
+ templates.each do |tmpl_file|
25
+
26
+ tmpl = File.read tmpl_file
27
+
28
+ erbTmpl = ERB.new tmpl
29
+
30
+ erbTmpl.result binding
31
+
32
+ tmpl_file = File.basename tmpl_file
33
+
34
+ output = erbTmpl.result binding
35
+
36
+ # Remove extenstion, and name propertly
37
+ tmpl_file.gsub!('template', @class_name).gsub!(File.extname(tmpl_file), '')
38
+
39
+
40
+
41
+ File.open(tmpl_file, 'w') { |file| file.write(output) }
42
+ end
43
+ end
44
+ end
45
+
46
+ def objc_attr_type(attr)
47
+ case attr.type
48
+ when :String, :Array
49
+ "NS#{attr.type}*"
50
+ when :Boolean
51
+ "BOOL"
52
+ when :Pointer
53
+ "PFObject*"
54
+ when :GeoPoint
55
+ "PFGeoPoint*"
56
+ when :Relation
57
+ "PFRelation*"
58
+ else
59
+ "?#{attr.type}?"
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def supported_types
66
+ @@supported_types
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,53 @@
1
+ module Parse
2
+ module Model
3
+ module Scaffold
4
+
5
+ class ParseInspector
6
+
7
+ Attribute = Struct.new :name, :type do
8
+ def to_s
9
+ self.name
10
+ end
11
+ end
12
+
13
+ @@protected_fields = ['objectId', 'createdAt', 'updatedAt', 'ACL']
14
+
15
+ def self.parse(obj)
16
+
17
+ @@protected_fields.each {|x| obj.delete x}
18
+
19
+ attrs = []
20
+
21
+ obj.each do |k, v|
22
+ value_type = determine_type(v)
23
+ attr = Attribute.new(k, value_type)
24
+ attrs << attr
25
+ end
26
+
27
+ attrs
28
+ end
29
+
30
+ # Map Parse types to Ruby types if possible, otherwise, leave them as a
31
+ def self.determine_type(val)
32
+
33
+ return val.class.to_s.to_sym if [String, Array].include? val.class
34
+
35
+ if val.is_a? Hash
36
+
37
+ # If we don't see the Parse '__type' key that they use for encoding
38
+ # complex types, then this is just a simple object
39
+ return Hash if !val.has_key? '__type'
40
+
41
+ # Otherwise, this is probably a Parse type (Relation, Pointer, GeoPoint, etc.)
42
+ return val['__type'].to_sym
43
+ end
44
+
45
+ return :Boolean if [TrueClass, FalseClass].include? val.class
46
+
47
+ # Last resort
48
+ val.class.to_s.to_sym
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,13 @@
1
+ if typeof window == 'undefined'
2
+ Parse = require('parse').Parse
3
+
4
+
5
+ <%= @class_name %> = Parse.Object.extend "<%= @class_name %>",
6
+ initialize: ->
7
+ @attrs =
8
+ <% @attrs.each do |attr| %>
9
+ <%= attr %>: (val) => if !val then @get '<%= attr %>' else @set '<%= attr %>', val
10
+ <% end %>
11
+
12
+ if typeof window == 'undefined'
13
+ module.exports = <%= @class_name %>
@@ -0,0 +1,16 @@
1
+ //
2
+ // <%= @class_name %>.h
3
+ //
4
+
5
+ #import <Foundation/Foundation.h>
6
+ #import <Parse/Parse.h>
7
+
8
+ @interface <%= @class_name %> : PFObject<PFSubclassing>
9
+
10
+ + (NSString *)parseClassName;
11
+
12
+ <% @attrs.each do |attr| %>
13
+ @property (nonatomic) <%= objc_attr_type(attr) %> <%= attr %>;
14
+ <% end %>
15
+
16
+ @end
@@ -0,0 +1,19 @@
1
+ //
2
+ // <%= @class_name %>.h
3
+ //
4
+
5
+ #import "<%= @class_name %>.h"
6
+ #import <Parse/PFObject+Subclass.h>
7
+
8
+ @implementation <%= @class_name %>
9
+
10
+ <% @attrs.each do |attr| %>
11
+ @dynamic <%= attr %>;
12
+ <% end %>
13
+
14
+ + (NSString *)parseClassName
15
+ {
16
+ return @"<%= @class_name %>";
17
+ }
18
+
19
+ @end
@@ -0,0 +1,7 @@
1
+ module Parse
2
+ module Model
3
+ module Scaffold
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ require 'parse-model-scaffold/parse_api'
2
+ require 'parse-model-scaffold/parse_inspector'
3
+ require 'parse-model-scaffold/parse_class_builder'
4
+
5
+ module Parse
6
+ module Model
7
+ module Scaffold
8
+ class PFScaffolder
9
+
10
+ def initialize(appId, apiKey)
11
+ @api = ParseApi.new appId, apiKey
12
+ end
13
+
14
+ def generate (class_names, types = nil)
15
+
16
+ class_names = [class_names] unless class_names.is_a?(Array)
17
+
18
+ class_names.each do |class_name|
19
+
20
+ sample_obj = @api.get_first class_name
21
+
22
+ next if !sample_obj # Should scream here
23
+
24
+ sample_attrs = ParseInspector.parse(sample_obj)
25
+
26
+ builder = ParseClassBuilder.new(class_name, sample_attrs)
27
+ builder.build types
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'parse-model-scaffold/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "parse-model-scaffold"
8
+ gem.version = Parse::Model::Scaffold::VERSION
9
+ gem.authors = ["Matt Hupman"]
10
+ gem.email = ["mhupman@citrrus.com"]
11
+ gem.description = %q{Tool to generate concrete subclasses of existing Parse.com model objects in a variety of languages.}
12
+ gem.summary = %q{Can be included as a library or exectued as a binary.}
13
+ gem.homepage = "https://github.com/mhupman/parse-model-scaffold"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'httparty'
21
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parse-model-scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Hupman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Tool to generate concrete subclasses of existing Parse.com model objects
31
+ in a variety of languages.
32
+ email:
33
+ - mhupman@citrrus.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - lib/parse-model-scaffold.rb
45
+ - lib/parse-model-scaffold/parse_api.rb
46
+ - lib/parse-model-scaffold/parse_class_builder.rb
47
+ - lib/parse-model-scaffold/parse_inspector.rb
48
+ - lib/parse-model-scaffold/templates/coffee/template.coffee.ejs
49
+ - lib/parse-model-scaffold/templates/objc/template.h.ejs
50
+ - lib/parse-model-scaffold/templates/objc/template.m.ejs
51
+ - lib/parse-model-scaffold/version.rb
52
+ - parse-model-scaffold.gemspec
53
+ homepage: https://github.com/mhupman/parse-model-scaffold
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.24
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Can be included as a library or exectued as a binary.
77
+ test_files: []