bowline 0.5.8 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/README.txt +2 -2
  2. data/Rakefile +3 -2
  3. data/TODO +2 -0
  4. data/VERSION +1 -1
  5. data/assets/bowline.js +131 -68
  6. data/assets/bowline.test.js +86 -0
  7. data/bowline.gemspec +15 -17
  8. data/examples/tweet.rb +3 -1
  9. data/lib/bowline.rb +9 -5
  10. data/lib/bowline/app_config.rb +41 -0
  11. data/lib/bowline/binders.rb +70 -101
  12. data/lib/bowline/binders/collection.rb +37 -0
  13. data/lib/bowline/binders/observer.rb +30 -0
  14. data/lib/bowline/binders/singleton.rb +43 -0
  15. data/lib/bowline/commands/run.rb +1 -0
  16. data/lib/bowline/desktop/bridge.rb +4 -4
  17. data/lib/bowline/desktop/js.rb +7 -3
  18. data/lib/bowline/desktop/runtime.rb +29 -0
  19. data/lib/bowline/desktop/window.rb +9 -1
  20. data/lib/bowline/desktop/window_methods.rb +1 -1
  21. data/lib/bowline/generators/application.rb +1 -0
  22. data/lib/bowline/generators/binder.rb +7 -2
  23. data/lib/bowline/generators/model.rb +1 -1
  24. data/lib/bowline/helpers.rb +2 -0
  25. data/lib/bowline/initializer.rb +39 -87
  26. data/lib/bowline/library.rb +1 -7
  27. data/lib/bowline/tasks/app.rake +1 -53
  28. data/lib/bowline/tasks/libs.rake +4 -17
  29. data/lib/bowline/version.rb +2 -2
  30. data/lib/bowline/watcher.rb +50 -23
  31. data/templates/Gemfile +10 -0
  32. data/templates/config/boot.rb +11 -8
  33. data/templates/main_window.rb +1 -0
  34. metadata +20 -15
  35. data/lib/bowline/dependencies/FAQ.markdown +0 -6
  36. data/lib/bowline/dependencies/MIT-LICENSE +0 -20
  37. data/lib/bowline/dependencies/README.markdown +0 -51
  38. data/lib/bowline/dependencies/TODO.markdown +0 -4
  39. data/lib/bowline/dependencies/lib/dependencies.rb +0 -6
  40. data/lib/bowline/dependencies/lib/dependencies/dependency.rb +0 -12
  41. data/lib/bowline/dependencies/lib/dependencies/repository.rb +0 -64
  42. data/lib/bowline/dependencies/lib/ext/rubygems.rb +0 -116
  43. data/lib/bowline/ext/class.rb +0 -51
  44. data/lib/bowline/ext/string.rb +0 -9
  45. data/lib/bowline/local_model.rb +0 -142
  46. data/lib/bowline/tasks/gems.rake +0 -36
@@ -1,51 +0,0 @@
1
- # Extends the class object with class and instance accessors for class attributes,
2
- # just like the native attr* accessors for instance attributes.
3
- #
4
- # class Person
5
- # cattr_accessor :hair_colors
6
- # end
7
- #
8
- # Person.hair_colors = [:brown, :black, :blonde, :red]
9
- class Class
10
- def cattr_reader(*syms)
11
- syms.flatten.each do |sym|
12
- next if sym.is_a?(Hash)
13
- class_eval(<<-EOS, __FILE__, __LINE__)
14
- unless defined? @@#{sym}
15
- @@#{sym} = nil
16
- end
17
-
18
- def self.#{sym}
19
- @@#{sym}
20
- end
21
-
22
- def #{sym}
23
- @@#{sym}
24
- end
25
- EOS
26
- end
27
- end
28
-
29
- def cattr_writer(*syms)
30
- syms.flatten.each do |sym|
31
- class_eval(<<-EOS, __FILE__, __LINE__)
32
- unless defined? @@#{sym}
33
- @@#{sym} = nil
34
- end
35
-
36
- def self.#{sym}=(obj)
37
- @@#{sym} = obj
38
- end
39
-
40
- def #{sym}=(obj)
41
- @@#{sym} = obj
42
- end
43
- EOS
44
- end
45
- end
46
-
47
- def cattr_accessor(*syms)
48
- cattr_reader(*syms)
49
- cattr_writer(*syms)
50
- end
51
- end
@@ -1,9 +0,0 @@
1
- class String
2
- def underscore
3
- self.gsub(/::/, '/').
4
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
- tr("-", "_").
7
- downcase
8
- end
9
- end
@@ -1,142 +0,0 @@
1
- module Bowline
2
- # The LocalModel class mirrors ActiveRecord's api, and is used for
3
- # models you want to hold in memory.
4
- #
5
- # You can also use this class in conjunction with Bowline's binders.
6
- #
7
- # All normal ActiveRecord callbacks are supported, such as before_save and after_save.
8
- #
9
- # Associations are not currently supported.
10
- class LocalModel
11
- extend Watcher::Base
12
-
13
- watch :before_save, :after_save,
14
- :before_create, :after_create,
15
- :before_update, :after_update,
16
- :before_destroy, :after_destroy
17
-
18
- class << self
19
- def records
20
- @records ||= []
21
- end
22
-
23
- # Populate the model with the array argument.
24
- # This doesn't replace the model's existing records.
25
- # Create callbacks are still executed.
26
- def populate(array)
27
- array.each {|r| create(r) }
28
- end
29
-
30
- # Find record by ID, or raise.
31
- def find(id)
32
- records.find {|r| r.id == id } || raise('Unknown Record')
33
- end
34
- alias :[] :find
35
-
36
- def first
37
- records[0]
38
- end
39
-
40
- def last
41
- records[-1]
42
- end
43
-
44
- def count
45
- records.length
46
- end
47
-
48
- def all
49
- records
50
- end
51
-
52
- def destroy(id)
53
- find(id).destroy
54
- end
55
-
56
- # Removes all records and executes
57
- # destory callbacks.
58
- def destroy_all
59
- records.dup.each {|r| r.destroy }
60
- end
61
-
62
- # Removes all records without executing
63
- # destroy callbacks.
64
- def delete_all
65
- records.clear
66
- end
67
-
68
- # Create a new record.
69
- # Example:
70
- # create(:name => "foo", :id => 1)
71
- def create(atts = {})
72
- rec = self.new(atts)
73
- rec.save && rec
74
- end
75
- end
76
-
77
- attr_reader :attributes
78
-
79
- # Initialize the record with an optional
80
- # hash of attributes. If a :id attribute
81
- # isn't passed, the instance's object id
82
- # is used instead.
83
- def initialize(atts = {})
84
- @attributes = {}.with_indifferent_access
85
- @attributes.replace(atts)
86
- @attributes[:id] ||= __id__
87
- @new_record = true
88
- end
89
-
90
- # Override __id__
91
- def id
92
- @attributes[:id]
93
- end
94
-
95
- # Update record with a hash of new attributes.
96
- def update(atts)
97
- run_callbacks(:before_save)
98
- run_callbacks(:before_update)
99
- attributes.merge!(atts)
100
- run_callbacks(:after_save)
101
- run_callbacks(:after_update)
102
- true
103
- end
104
-
105
- def save
106
- run_callbacks(:before_save)
107
- if @new_record
108
- run_callbacks(:before_create)
109
- self.class.records << self
110
- run_callbacks(:after_create)
111
- @new_record = false
112
- end
113
- run_callbacks(:after_save)
114
- true
115
- end
116
-
117
- def destroy
118
- run_callbacks(:before_destroy)
119
- self.class.records.delete(self)
120
- run_callbacks(:after_destroy)
121
- true
122
- end
123
-
124
- def method_missing(method_symbol, *arguments) #:nodoc:
125
- method_name = method_symbol.to_s
126
-
127
- case method_name.last
128
- when "="
129
- attributes[method_name.first(-1)] = arguments.first
130
- when "?"
131
- attributes[method_name.first(-1)]
132
- else
133
- attributes.has_key?(method_name) ? attributes[method_name] : super
134
- end
135
- end
136
-
137
- private
138
- def run_callbacks(callback)
139
- self.class.watcher.call(callback, self)
140
- end
141
- end
142
- end
@@ -1,36 +0,0 @@
1
- namespace :gems do
2
- desc "Install gems locally"
3
- task :sync => [:environment] do
4
- require 'bowline/dependencies/lib/ext/rubygems'
5
-
6
- conf = Bowline.configuration
7
- repo = Dependencies::Repository.new(
8
- conf.gem_path
9
- )
10
-
11
- conf.gems.each do |dep|
12
- gem = repo.gem(dep.name, dep.versions)
13
- next unless repo.search(gem).empty?
14
- repo.install(gem)
15
- end
16
-
17
- repo.reload_index!
18
-
19
- full_list = conf.gems.map do |dep|
20
- gem = repo.gem(dep.name, dep.versions)
21
- spec = repo.index.search(gem).last
22
- unless spec
23
- raise Exception.new("A required dependency #{gem} was not found")
24
- end
25
- deps = spec.recursive_dependencies(gem, repo.index)
26
- [spec] + deps
27
- end.flatten.uniq.map do |spec|
28
- "#{spec.name}-#{spec.version}"
29
- end
30
-
31
- (repo.installed - full_list).each do |g|
32
- /^(.*)\-(.*)$/ =~ g
33
- repo.uninstall($1, $2)
34
- end
35
- end
36
- end