Class: IB::Parser
- Inherits:
-
Object
- Object
- IB::Parser
- Defined in:
- lib/ib/parser.rb
Constant Summary collapse
- NAME_REGEX =
/[a-zA-Z][_a-zA-Z0-9]*/
- CLASS_REGEX =
/^[ \t]*class[ \t]+(#{NAME_REGEX})[ \t]*<[ \t]*(#{NAME_REGEX})/
- OUTLET_REGEX =
/^[ \t]+(ib_)?outlet(_accessor)?[ \t]+:(#{NAME_REGEX})[ \t]*?(,[ \t]*['"]?(#{NAME_REGEX}))?/
- OUTLET_COLLECTION_REGEX =
/^[ \t]+(ib_)?outlet_collection(_accessor)?[ \t]+:(#{NAME_REGEX})[ \t]*?(,[ \t]*['"]?(#{NAME_REGEX}))?/
- METHOD_REF_REGEX =
/^[ \t]+(ib_action)[ \t]:(#{NAME_REGEX})/
- METHOD_DEF_REGEX =
/^[ \t]+(def)[ \t](#{NAME_REGEX})([ \t(]+)?(#{NAME_REGEX})?([ \t)]*)(#.*)?$/
- ACTION_REGEX =
Regexp.union METHOD_DEF_REGEX, METHOD_REF_REGEX
Instance Method Summary collapse
- #find(path) ⇒ Object
- #find_actions(src) ⇒ Object
- #find_all(dir) ⇒ Object
- #find_class(src) ⇒ Object
- #find_outlet_collections(src) ⇒ Object
- #find_outlets(src) ⇒ Object
Instance Method Details
#find(path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ib/parser.rb', line 20 def find(path) src = File.read(path) info = {class: find_class(src)} return false if info[:class].length == 0 info[:outlets] = find_outlets(src) info[:outlet_collections] = find_outlet_collections(src) info[:actions] = find_actions(src) info[:path] = path info end |
#find_actions(src) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ib/parser.rb', line 51 def find_actions src src.scan(ACTION_REGEX).map do |groups| if groups[0] == "def" [groups[1], groups[3]] elsif groups[6] == "ib_action" [groups[7], 'sender'] else nil end end.compact.uniq {|action| action[0]} end |
#find_all(dir) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/ib/parser.rb', line 10 def find_all(dir) all = {} Dir.glob("#{dir}/**/*.rb") do |file| if info = find(file) all[file] = info end end all end |
#find_class(src) ⇒ Object
35 36 37 |
# File 'lib/ib/parser.rb', line 35 def find_class src src.scan CLASS_REGEX end |
#find_outlet_collections(src) ⇒ Object
45 46 47 48 49 |
# File 'lib/ib/parser.rb', line 45 def find_outlet_collections src src.scan(OUTLET_COLLECTION_REGEX).map do |groups| [groups[2], groups[4] || "id"] end end |
#find_outlets(src) ⇒ Object
39 40 41 42 43 |
# File 'lib/ib/parser.rb', line 39 def find_outlets src src.scan(OUTLET_REGEX).map do |groups| [groups[2], groups[4] || "id"] end end |