motion-rails-model 0.0.1 → 0.0.1.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 CHANGED
@@ -15,3 +15,8 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .repl_history
19
+ build
20
+ resources/*.nib
21
+ resources/*.momd
22
+ resources/*.storyboardc
data/Rakefile CHANGED
@@ -1,25 +1,10 @@
1
- #!/usr/bin/env rake
1
+ # -*- coding: utf-8 -*-
2
2
  $:.unshift("/Library/RubyMotion/lib")
3
3
  require 'motion/project'
4
- Bundler.setup
4
+ require 'rubygems'
5
5
  Bundler.require
6
6
 
7
- require 'bubble-wrap/all'
8
- require 'bubble-wrap/test'
9
-
10
7
  Motion::Project::App.setup do |app|
11
- app.name = 'testSuite'
12
- app.identifier = 'io.bubblewrap.testSuite'
13
- app.specs_dir = './spec/motion'
14
- app.version = '1.2.3'
15
- end
16
-
17
- namespace :spec do
18
- task :lib do
19
- sh "bacon #{Dir.glob("spec/lib/**/*_spec.rb").join(' ')}"
20
- end
21
-
22
- task :motion => 'spec'
23
-
24
- task :all => [:lib, :motion]
25
- end
8
+ # Use `rake config' to see complete project settings.
9
+ app.name = 'modeltest'
10
+ end
@@ -0,0 +1,8 @@
1
+ class AppDelegate
2
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
3
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
4
+ @window.rootViewController = UIViewController.alloc.init
5
+ @window.makeKeyAndVisible
6
+ true
7
+ end
8
+ end
@@ -0,0 +1,82 @@
1
+ module RM
2
+ class Model
3
+ attr_accessor :id
4
+ @@url = ""
5
+ @@username = ""
6
+ @@password = ""
7
+
8
+ def initialize(json={})
9
+ attributes_update(json)
10
+ end
11
+
12
+ def self.find(id, &block)
13
+ x = self.new
14
+ x.fetch("#{x.class.to_s.downcase}/#{id}") do |y|
15
+ block.call(y)
16
+ end
17
+ end
18
+
19
+ def self.all(&block)
20
+ x = self.new
21
+ x.fetch("#{x.class.to_s.downcase}") do |y|
22
+ block.call(y)
23
+ end
24
+ end
25
+
26
+ def save(url="#{self.class.to_s.downcase}#{('/' + self.id.to_s) if self.id}", &block)
27
+ type = (self.id.nil?)? "post": "put"
28
+ data = {"_method" => type}
29
+ keys = {}
30
+ self.instance_variables.map do |x|
31
+ y = x.to_s.sub(/@/, "")
32
+ z = self.send(y)
33
+ keys.merge!({ y => z}) unless z.nil?
34
+ end
35
+ data.merge!(self.class.to_s.downcase => keys)
36
+ connect(url, data, type) do |result|
37
+ block.call(result)
38
+ end
39
+ end
40
+
41
+ def self.set_url(url)
42
+ @@url = url
43
+ end
44
+
45
+ def self.set_username(username)
46
+ @@username = username
47
+ end
48
+
49
+ def self.set_password(password)
50
+ @@password = password
51
+ end
52
+
53
+ def fetch(url="#{self.class.to_s.downcase}/#{self.id}", &block)
54
+ data = { credentials: {username: @@username, password: @@password}}
55
+ connect(url, data, :get) do |result|
56
+ block.call(result)
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def attributes_update(json)
63
+ @id = json['id']
64
+ end
65
+
66
+ def connect(url, data, http_verb, &block)
67
+ BW::HTTP.send(http_verb, "#{@@url}#{url}", data) do |response|
68
+ if response.ok?
69
+ json = BW::JSON.parse(response.body.to_str)
70
+ if json.instance_of?(Array)
71
+ block.call(json.map {|y| self.class.new(y) })
72
+ else
73
+ block.call(self.class.new(json))
74
+ end
75
+ else
76
+ raise response.status_code
77
+ end
78
+ end
79
+ end
80
+
81
+ end
82
+ end
@@ -1,5 +1,5 @@
1
1
  module RM
2
2
  class Model
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.1.1"
4
4
  end
5
5
  end
data/spec/main_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ describe "Application 'modeltest'" do
2
+ before do
3
+ @app = UIApplication.sharedApplication
4
+ end
5
+
6
+ it "has one window" do
7
+ @app.windows.size.should == 1
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-rails-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -39,9 +39,12 @@ files:
39
39
  - LICENSE
40
40
  - README.md
41
41
  - Rakefile
42
+ - app/app_delegate.rb
42
43
  - lib/motion-rails-model.rb
44
+ - lib/motion-rails-model/model.rb
43
45
  - lib/motion-rails-model/version.rb
44
46
  - motion-rails-model.gemspec
47
+ - spec/main_spec.rb
45
48
  homepage: https://github.com/face-do
46
49
  licenses: []
47
50
  post_install_message:
@@ -66,5 +69,6 @@ rubygems_version: 1.8.24
66
69
  signing_key:
67
70
  specification_version: 3
68
71
  summary: likes rails model
69
- test_files: []
72
+ test_files:
73
+ - spec/main_spec.rb
70
74
  has_rdoc: