Giter VIP home page Giter VIP logo

motion-env's Introduction

motion-env

gem install motion-env

In your Rakefile:

require 'motion-env'

Motion::Project::App.setup do |app|
  app.env['string'] = "Sup dog"
  app.env["int"] = 3
  app.env["bool"] = false
  app.env['hash'] = {herp: "derp"}
  app.env["array"] = [1,2,3]
  app.env["complex"] = [{hello: "world", array: [1,2,3]}, {something: :else}]
end

(app.ENV will also work, if you prefer symmetry)

In your app:

> ENV['string']
=> "Sup dog"
> ENV['int']
=> 3
> ENV['bool']
=> false
> ENV['hash']
=> {:herp=>"derp"}
> ENV['array']
=> [1, 2, 3]
> ENV['complex']
=> [{:hello=>"world", :array=>[1, 2, 3]}, {:something=>:else}]

How?

wtf

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 for implementation.

That means you can also Marshal POROs, assuming the class exists on both sides of the compilation:

class Person
  attr_accessor :name, :age

  def initialize(name, age)
    @name = name
    @age = age
  end
end

Motion::Project::App.setup do |app|
  app.env["object"] = Person.new("clay", 3)
end
> ENV["object"] # assumes you have Person defined somewhere
=> #<Person:0x8e62da0 @name="clay" @age=3>

Support

Big thanks to motion-my_env and @ainame for the inspiration.

Clay Allsopp

motion-env's People

Contributors

clayallsopp avatar rromanchuk avatar

Stargazers

Jeremiah Parrack avatar  avatar Igor Putina avatar Minku Lee avatar Evgeny Erohin avatar Vaughan Kelly Guy avatar Andrew Havens avatar Chris McKnight avatar Qi He avatar ✨ Kathryn Gonzalez ✨ avatar Burin Choomnuan avatar Kevin Fagan avatar Kyrylo Savytskyi avatar Satoshi Namai avatar Volkan Unsal avatar Chris Hunter avatar kyamaguchi avatar Libin Pan avatar Andrew Gertig avatar HH avatar Ethan Sherbondy avatar Bill Gloff avatar Elliott Draper avatar Michael Erb avatar James Miller avatar Melvyn Hills avatar Mark Rickert avatar Gerald Philip MacKenzie avatar Eric Gallager avatar  avatar Watson avatar

Watchers

 avatar Liu Lantao avatar James Cloos avatar  avatar  avatar

motion-env's Issues

Using motion-env with extensions breaks the build build

running https://github.com/HipByte/RubyMotionSamples/tree/master/ios/ExtensionsAndFrameworks works fine. As soon as you add 'motion-env' to your gemfile the build breaks

➜  ExtensionsAndFrameworks git:(master) ✗ rake
     Build ./build/iPhoneSimulator-8.0-Development
rake aborted!
NoMethodError: undefined method `variable' for Motion::Project::IOSConfig:Class
/Users/ryan/.rvm/gems/ruby-2.1.0/gems/motion-env-0.0.3/lib/motion-env/ios.rb:3:in `<class:IOSConfig>'
/Users/ryan/.rvm/gems/ruby-2.1.0/gems/motion-env-0.0.3/lib/motion-env/ios.rb:2:in `<module:Project>'
/Users/ryan/.rvm/gems/ruby-2.1.0/gems/motion-env-0.0.3/lib/motion-env/ios.rb:1:in `<module:Motion>'
/Users/ryan/.rvm/gems/ruby-2.1.0/gems/motion-env-0.0.3/lib/motion-env/ios.rb:1:in `<top (required)>'
/Users/ryan/.rvm/gems/ruby-2.1.0/gems/motion-env-0.0.3/lib/motion-env.rb:5:in `require'
/Users/ryan/.rvm/gems/ruby-2.1.0/gems/motion-env-0.0.3/lib/motion-env.rb:5:in `<top (required)>'
/Users/ryan/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
/Users/ryan/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
/Users/ryan/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
/Users/ryan/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
/Users/ryan/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
/Users/ryan/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
/Users/ryan/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
/Users/ryan/dev/RubyMotionSamples/ios/ExtensionsAndFrameworks/extensions/today-extension/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
    ERROR! Target 'extensions/today-extension' failed to build

Warning when storing an array of hashes with the same four keys

I think this might be a Ruby/Marshal issue, but when attempting to store an array of hashes with at least four identical string keys, running rake yields the following warning:

(ripper):13: warning: encountered \r in middle of line, treated as a mere space
   Compile /tmp/motion_env_1419972708.rb

Indeed, if you inspec the /tmp/motion_env_<timestamp>.rb file that's generated, the newline-ish \r character is there. This warning only seems to show up with four or more identical keys in hashes within an array, and doesn't seem related to the length of said identical keys.

I've created a gist with a Rakefile to illustrate the warning case:

https://gist.github.com/mwise/dd1d9a5fab19f229d09f

The array seems to be stored and retrieved correctly, so this is likely a non-fix or at least a low-priority one. I thought it was interesting, though - kind of made me feel like the WTF guy from the README.

Cheers,
Mark

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.