const_cache 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/README.md +29 -0
- data/lib/const_cache.rb +9 -0
- data/lib/motion/const_cache.rb +42 -0
- metadata +70 -0
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# const_cache
|
2
|
+
|
3
|
+
Cache slow constant lookups in a static data structure to speed up application launch in RubyMotion apps.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'const_cache'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install const_cache
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
There is nothing to do except require the gem. It will generate an `app/_const_cache.rb` file at runtime that is compiled on the next build that populates the constant cache on launch.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/lib/const_cache.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
app.info_plist['APP_ROOT'] = Dir.pwd
|
8
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "motion/**/*.rb")))
|
9
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ConstCache
|
2
|
+
module_function
|
3
|
+
|
4
|
+
def cache
|
5
|
+
@cache ||= Hash.new { |h, k| h[k] = {} }
|
6
|
+
end
|
7
|
+
|
8
|
+
def dump
|
9
|
+
return unless File.exist?(NSBundle.mainBundle.objectForInfoDictionaryKey('APP_ROOT'))
|
10
|
+
|
11
|
+
File.open("#{NSBundle.mainBundle.objectForInfoDictionaryKey('APP_ROOT')}/app/_const_cache.rb", 'w') do |file|
|
12
|
+
file.puts "# This file was auto-generated. All changes will be overwritten!"
|
13
|
+
file.puts
|
14
|
+
cache.each do |namespace, hash|
|
15
|
+
hash.each do |const_name, const|
|
16
|
+
file.puts "ConstCache.cache[#{namespace.inspect}][#{const_name.inspect}] = lambda { #{namespace}::#{const_name} }"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Object
|
24
|
+
def self.const_get_with_cache(const, inherit = true)
|
25
|
+
return const_get_without_cache(const, false) unless inherit
|
26
|
+
|
27
|
+
if result = ConstCache.cache[self.name][const]
|
28
|
+
result.call
|
29
|
+
else
|
30
|
+
ConstCache.cache[self.name][const] = lambda { const_get_without_cache(const, true) }
|
31
|
+
|
32
|
+
ConstCache.dump if Object.const_defined?(:RUBYMOTION_ENV) && RUBYMOTION_ENV == 'development'
|
33
|
+
|
34
|
+
ConstCache.cache[self.name][const].call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
alias_method :const_get_without_cache, :const_get
|
40
|
+
alias_method :const_get, :const_get_with_cache
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: const_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Kadauke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
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: Cache dynamic constant lookups in RubyMotion
|
31
|
+
email:
|
32
|
+
- tkadauke@imedo.de
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- README.md
|
38
|
+
- lib/const_cache.rb
|
39
|
+
- lib/motion/const_cache.rb
|
40
|
+
homepage: https://github.com/tkadauke/const_cache
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
hash: -907334696594588064
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
hash: -907334696594588064
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.25
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Cache dynamic constant lookups in RubyMotion
|
70
|
+
test_files: []
|