Permalink
Browse files

all the things

  • Loading branch information...
0 parents commit c2bfc1e42b3ad2155fde09d371faf2651ab9b691 @clayallsopp committed Sep 21, 2012
@@ -0,0 +1,6 @@
+.repl_history
+build
+resources/*.nib
+resources/*.momd
+resources/*.storyboardc
+.DS_Store
14 Gemfile
@@ -0,0 +1,14 @@
+# A sample Gemfile
+source "https://rubygems.org"
+
+# gem "rails"
+
+gem "formotion"
+
+gem "remote_model", ">=0.0.4"
+
+gem "routable"
+
+gem "bubble-wrap"
+
+gem "motion_support"
@@ -0,0 +1,21 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ bubble-wrap (1.1.3)
+ formotion (1.1)
+ bubble-wrap (>= 1.1.2)
+ motion_support (0.0.7)
+ bubble-wrap
+ remote_model (0.0.4)
+ bubble-wrap
+ routable (0.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bubble-wrap
+ formotion
+ motion_support
+ remote_model (>= 0.0.4)
+ routable
@@ -0,0 +1,12 @@
+$:.unshift("/Library/RubyMotion/lib")
+require 'motion/project'
+require "bundler/gem_tasks"
+require "bundler/setup"
+
+$:.unshift("./lib/")
+require './lib/maglev'
+
+Motion::Project::App.setup do |app|
+ # Use `rake config' to see complete project settings.
+ app.name = 'maglev'
+end
@@ -0,0 +1,30 @@
+class CamelCaseModel < Maglev::Model
+ has_one :another_camel_case_model
+ has_many :bunch_of_camel_case_models
+end
+
+class AnotherCamelCaseModel < Maglev::Model
+ remote_attributes :id
+
+ belongs_to :camel_case_model
+end
+
+class BunchOfCamelCaseModel < Maglev::Model
+ belongs_to :camel_case_model
+end
+
+class AppDelegate
+ attr_reader :user
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
+
+ #@user = User.new(id: 5, name: "Clay", bio: "Herp")
+ #@view_controller = Maglev::ModelController.for(self.user)
+
+ #@view_controller = Maglev::ListController.for(Movie, display_key: :name)
+ #@window.rootViewController = @view_controller
+ @window.makeKeyAndVisible
+
+ true
+ end
+end
@@ -0,0 +1,11 @@
+require "maglev/version"
+require 'bubble-wrap/core'
+require 'remote_model'
+require 'formotion'
+
+BW.require File.expand_path('../maglev/**/*.rb', __FILE__) do
+ ["attributes", "hashable", "relationships"].each do |f|
+ file("lib/maglev/model/#{f}.rb").depends_on file("lib/maglev/support.rb")
+ file("lib/maglev/model.rb").depends_on file("lib/maglev/model/#{f}.rb")
+ end
+end
@@ -0,0 +1,6 @@
+module Maglev
+ module API
+ def setup(&block)
+ end
+ end
+end
@@ -0,0 +1,5 @@
+module Maglev
+ module Error
+ class InvalidClassError < StandardError; end
+ end
+end
@@ -0,0 +1,15 @@
+module Maglev
+ module_function
+
+ def force_remote_relationship_syntax
+ @force_remote_relationship_syntax
+ end
+
+ def force_remote_relationship_syntax=(v)
+ @force_remote_relationship_syntax = v
+ end
+
+ def models
+ Maglev::Model.models
+ end
+end
@@ -0,0 +1,49 @@
+module Maglev
+ class Model
+ class << self
+ include Maglev::Attributes
+ include Maglev::Relationships
+
+ if !Maglev.force_remote_relationship_syntax
+ alias_method :has_many, :remote_has_many
+ alias_method :has_one, :remote_has_one
+ alias_method :has_one?, :remote_has_one?
+ alias_method :belongs_to, :remote_belongs_to
+ alias_method :belongs_to?, :remote_belongs_to?
+ end
+
+ attr_accessor :models
+
+ def models
+ @models ||= []
+ end
+
+ def inherited(subclass)
+ self.models << subclass
+ end
+
+ def snake_case
+ inspect.underscore
+ end
+ end
+
+ include Maglev::Hashable
+ include Maglev::RelationshipsInstance
+
+ [:remote_has_many, :remote_has_one, :remote_belongs_to].each do |relationship|
+ self.send(:define_method, relationship.to_s) do
+ h = {}
+ self.class.send(relationship).each do |name, hash|
+ h[name] = self.send(name)
+ end
+ h
+ end
+ end
+
+ if !Maglev.force_remote_relationship_syntax
+ alias_method :has_many, :remote_has_many
+ alias_method :has_one, :remote_has_one
+ alias_method :belongs_to, :remote_belongs_to
+ end
+ end
+end
@@ -0,0 +1,28 @@
+module Maglev
+ module Attributes
+ # Arguments will:
+ # - be normal ruby attributes
+ def remote_attributes(*args)
+ @remote_attributes ||= []
+ args.each do |arg|
+ remote_attribute(arg)
+ end
+ @remote_attributes
+ end
+
+ # EX
+ # remote_attribute :name
+ # EX
+ # remote_attribute :name, json_path: "username"
+ # EX
+ # remote_attribute :name do |json|
+ # self.name = json["first_name"] + json["last_name"]
+ # end
+ def remote_attribute(name, options = {})
+ @remote_attributes ||= []
+ attr_accessor name
+ @remote_attributes << { (options[:json_path] || name.to_sym) => name }
+ @remote_attributes
+ end
+ end
+end
@@ -0,0 +1,16 @@
+module Maglev
+ module Hashable
+ def initialize(properties = {})
+ update_attributes(properties)
+ end
+
+ def update_attributes(properties = {})
+ attributes = self.methods - Object.methods
+ properties.each do |key, value|
+ if attributes.member?("#{key}=:".to_sym)
+ self.send("#{key}=:".to_sym, value)
+ end
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit c2bfc1e

Please sign in to comment.