motion-env 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e7939f4f64183ce081230914ff2af9c0a19b905
4
+ data.tar.gz: 4db4365eade8e759878f088255ff6c4a82ea9807
5
+ SHA512:
6
+ metadata.gz: a5a30de7157ebb32fa8f2aba8b2e6a37eff27a48cd3b41e732f4adb3074a8a7338b2c759fa7400a3fefda985893e287bf11a3ea4ccd41e4b16939bf579af54ff
7
+ data.tar.gz: 1ece939c2823090bb9a0f37c58c2801f8b78e776cbacc89e8224a5ac6317acb43106fc1016f8abe795d5ad98b48fba8dc639cc42b4fcab21bad3b29a2f4cbdf5
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ .repl_history
2
+ build
3
+ tags
4
+ app/pixate_code.rb
5
+ resources/*.nib
6
+ resources/*.momd
7
+ resources/*.storyboardc
8
+ .DS_Store
9
+ nbproject
10
+ .redcar
11
+ #*#
12
+ *~
13
+ *.sw[po]
14
+ .eprj
15
+ .sass-cache
16
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Add your dependencies here:
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ motion-env (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ motion-env!
16
+ rake
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # motion-env
2
+
3
+ `gem install motion-env`
4
+
5
+ In your `Rakefile`:
6
+
7
+ ```ruby
8
+ require 'motion-env'
9
+
10
+ Motion::Project::App.setup do |app|
11
+ app.env['string'] = "Sup dog"
12
+ app.env["int"] = 3
13
+ app.env["bool"] = false
14
+ app.env['hash'] = {herp: "derp"}
15
+ app.env["array"] = [1,2,3]
16
+ app.env["complex"] = [{hello: "world", array: [1,2,3]}, {something: :else}]
17
+ end
18
+ ```
19
+
20
+ (`app.ENV` will also work, if you prefer symmetry)
21
+
22
+ In your app:
23
+
24
+ ```ruby
25
+ > ENV['string']
26
+ => "Sup dog"
27
+ > ENV['int']
28
+ => 3
29
+ > ENV['bool']
30
+ => false
31
+ (main)> ENV['hash']
32
+ => {:herp=>"derp"}
33
+ > ENV['array']
34
+ => [1, 2, 3]
35
+ > ENV['complex']
36
+ => [{:hello=>"world", :array=>[1, 2, 3]}, {:something=>:else}]
37
+ ```
38
+
39
+ # How?
40
+
41
+ ![wtf](http://i.imgur.com/e0nv2G9.gif)
42
+
43
+ motion-env takes whatever you put in `app.env` and `Marshal`'s the contents into `ENV` via code generation. At the same time, it swizzles `[](key)` to un-marshal the value (if appropriate). See [builder.rb](lib/motion-env/builder.rb) for implementation.
44
+
45
+ That means you can also Marshal POROs, assuming the class exists on both sides of the compilation:
46
+
47
+ ```ruby
48
+ class Person
49
+ attr_accessor :name, :age
50
+
51
+ def initialize(name, age)
52
+ @name = name
53
+ @age = age
54
+ end
55
+ end
56
+
57
+ Motion::Project::App.setup do |app|
58
+ app.env["object"] = Person.new("clay", 3)
59
+ end
60
+ ```
61
+
62
+ ```ruby
63
+ > ENV["object"] # assumes you have Person defined somewhere
64
+ => #<Person:0x8e62da0 @name="clay" @age=3>
65
+ ```
66
+
67
+ # Support
68
+
69
+ Big thanks to [motion-my_env](https://github.com/ainame/motion-my_env) and [@ainame](https://twitter.com/ainame) for the inspiration.
70
+
71
+ [Clay Allsopp](http://clayallsopp.com/)
72
+ - [clay@usepropeller.com](mailto:clay@usepropeller.com)
73
+ - [@clayallsopp](https://twitter.com/clayallsopp)
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+ $:.unshift("/Library/RubyMotion/lib")
3
+ require 'motion/project/template/ios'
4
+
5
+ require "bundler/gem_tasks"
6
+ require "bundler/setup"
7
+
8
+
9
+ begin
10
+ require 'bundler'
11
+ Bundler.require
12
+ rescue LoadError
13
+ end
14
+
15
+ Motion::Project::App.setup do |app|
16
+ # Use `rake config' to see complete project settings.
17
+ app.name = 'motion-env'
18
+
19
+ app.ENV['hash'] = {herp: "derp"}
20
+ app.env['string'] = "Sup dog"
21
+ app.env["int"] = 3
22
+ app.env["bool"] = false
23
+ app.env["array"] = [1,2,3]
24
+ app.env["complex"] = [{hello: "world", array: [1,2,3]}, {something: :else}]
25
+
26
+ class Person
27
+ attr_accessor :name, :age
28
+
29
+ def initialize(name, age)
30
+ @name = name
31
+ @age = age
32
+ end
33
+ end
34
+
35
+ app.env["object"] = Person.new("clay", 3)
36
+ end
@@ -0,0 +1,28 @@
1
+ class Person
2
+ attr_accessor :name, :age
3
+ end
4
+
5
+ class AppDelegate
6
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
7
+ puts ENV['hello world']
8
+
9
+ expected = [
10
+ ['string', "Sup dog"],
11
+ ['int', 3],
12
+ ['bool', false],
13
+ ['hash', {:herp=>"derp"}],
14
+ ['array', [1,2,3]],
15
+ ['complex', [{:hello=>"world", :array=>[1, 2, 3]}, {:something=>:else}]]
16
+ ]
17
+
18
+ expected.each do |key, value|
19
+ real_value = ENV[key]
20
+ raise "Incorrect! Key: #{key} Expected: #{value} Actual: #{real_value}" if value != real_value
21
+ end
22
+
23
+ person = ENV['object']
24
+ raise "Incorrect object unmarshal" if !person.is_a?(Person) || person.name != 'clay' || person.age != 3
25
+
26
+ true
27
+ end
28
+ end
data/lib/motion-env.rb ADDED
@@ -0,0 +1,6 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ require 'motion-env/ios'
6
+ require 'motion-env/builder'
@@ -0,0 +1,35 @@
1
+ module Motion; module Project;
2
+ class Builder
3
+ MARSHAL_SIGIL = "__marshall__"
4
+ def build_with_env(config, platform, opts)
5
+ config_env = config.env
6
+ File.open(config_env.file_path, 'w') { |f|
7
+ f.write %Q{
8
+ ENV.instance_variable_set("@get_key_without_patch", ENV.method(:[]))
9
+ ENV.instance_eval do
10
+ def [](key)
11
+ value = @get_key_without_patch.call(key)
12
+ if value && value.start_with?("#{MARSHAL_SIGIL}")
13
+ value = Marshal.load(value.gsub("#{MARSHAL_SIGIL}", ""))
14
+ end
15
+ value
16
+ end
17
+ end
18
+ }
19
+ config_env.each do |key, value|
20
+ dump_value = value
21
+ if !value.is_a?(String)
22
+ dump_value = MARSHAL_SIGIL + Marshal.dump(value)
23
+ end
24
+ f.write "ENV['#{key.to_s}'] = '#{dump_value}'\n"
25
+ end
26
+ }
27
+ config.files << config_env.file_path
28
+
29
+ build_without_env(config, platform, opts)
30
+ end
31
+
32
+ alias_method "build_without_env", "build"
33
+ alias_method "build", "build_with_env"
34
+ end
35
+ end; end
@@ -0,0 +1,24 @@
1
+ module Motion; module Project;
2
+ class IOSConfig
3
+ variable :env
4
+
5
+ class EnvWrapper < Hash
6
+ attr_accessor :timestamp
7
+
8
+ def initialize(*args)
9
+ super
10
+ @timestamp = Time.now.to_i
11
+ end
12
+
13
+ def file_path
14
+ @file_path ||= "/tmp/motion_env_#{@timestamp}.rb"
15
+ end
16
+ end
17
+
18
+ def env
19
+ @env ||= EnvWrapper.new
20
+ end
21
+
22
+ alias_method :ENV, :env
23
+ end
24
+ end; end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "motion-env"
5
+ s.version = "0.0.1"
6
+ s.authors = ["Clay Allsopp"]
7
+ s.email = ["clay@usepropeller.com"]
8
+ s.homepage = "https://github.com/usepropeller/motion-env"
9
+ s.summary = "Add things to ENV in RubyMotion"
10
+ s.description = "Add things to ENV in RubyMotion"
11
+
12
+ s.files = `git ls-files`.split($\)
13
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
14
+ s.require_paths = ["lib"]
15
+ s.license = 'MIT'
16
+
17
+ s.add_development_dependency 'rake'
18
+ end
Binary file
data/spec/main_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ describe "Application 'motion-env'" 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 ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-env
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Clay Allsopp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Add things to ENV in RubyMotion
28
+ email:
29
+ - clay@usepropeller.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - README.md
38
+ - Rakefile
39
+ - app/app_delegate.rb
40
+ - lib/motion-env.rb
41
+ - lib/motion-env/builder.rb
42
+ - lib/motion-env/ios.rb
43
+ - motion-env.gemspec
44
+ - resources/Default-568h@2x.png
45
+ - spec/main_spec.rb
46
+ homepage: https://github.com/usepropeller/motion-env
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.0.3
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Add things to ENV in RubyMotion
70
+ test_files:
71
+ - spec/main_spec.rb